Docker容器部署WordPress 仅仅做测试使用

Docker容器化应用 :
*部署docker环境
注意事项:
建议使用Centos7-1810版本 在1511版本会出现驱动问题和iptables问题
1.先配置网络的yum文件:不会的可以参考这篇文档 https://blog.csdn.net/smileui/article/details/106738039

yum clean all<span class="token punctuation">;</span> yum makecache
yum clean all<span class="token punctuation">;</span> yum makecache 
yum clean all; yum makecache

2.安装docker环境:

yum <span class="token function">install</span> -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum <span class="token function">install</span> docker-ce docker-ce-cli containerd.io -y systemctl start docker systemctl <span class="token function">enable</span> docker
yum <span class="token function">install</span> -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum <span class="token function">install</span> docker-ce docker-ce-cli containerd.io -y systemctl start docker systemctl <span class="token function">enable</span> docker 
yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install docker-ce docker-ce-cli containerd.io -y systemctl start docker systemctl enable docker

3…配置国内的仓库地址:实现快速部署镜像

<span class="token function">sudo</span> <span class="token function">mkdir</span> -p /etc/docker <span class="token function">sudo</span> <span class="token function">tee</span> /etc/docker/daemon.json <span class="token operator"><<</span>-<span class="token string">'EOF'</span> <span class="token punctuation">{<!-- --></span> <span class="token string">"registry-mirrors"</span><span class="token keyword">:</span> <span class="token punctuation">[</span><span class="token string">"https://2n9uoybw.mirror.aliyuncs.com"</span><span class="token punctuation">]</span> <span class="token punctuation">}</span> EOF
<span class="token function">sudo</span> <span class="token function">mkdir</span> -p /etc/docker <span class="token function">sudo</span> <span class="token function">tee</span> /etc/docker/daemon.json <span class="token operator"><<</span>-<span class="token string">'EOF'</span> <span class="token punctuation">{<!-- --></span> <span class="token string">"registry-mirrors"</span><span class="token keyword">:</span> <span class="token punctuation">[</span><span class="token string">"https://2n9uoybw.mirror.aliyuncs.com"</span><span class="token punctuation">]</span> <span class="token punctuation">}</span> EOF 
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://2n9uoybw.mirror.aliyuncs.com"] } EOF

4.重现启动服务

systemctl daemon-reload <span class="token operator">&&</span> systemctl restart docker
systemctl daemon-reload <span class="token operator">&&</span> systemctl restart docker 
systemctl daemon-reload && systemctl restart docker

准备部署wordpress需要的镜像文件
wordpress 基于 PHP+MySQL开发的一套博客系统,如果想运行需要使用LAMP或LNMP wordpress:latest 默认已经包含了AP或NP
mysql:5.7 安装MySQL数据库,建议使用5.6或5.7版本

[root@localhost ~]# docker pull wordpress:latest
[root@localhost ~]# docker pull mysql:5.7

一、 准备docker-compose工具
为接下来启动容器进行编排(类似日常生活中的工作计划)
LAMP 先启动mysql,再启动apache
部署wordpress应用时,应该先启动mysql容器,再启动wordpress

<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> REPOSITORY TAG IMAGE ID CREATED SIZE wordpress latest ee025cbcbc20 3 days ago 539MB mysql 5.7 1e4405fe1ea9 2 weeks ago 437MB centos latest 0f3e07c0138f 2 months ago 220MB
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> REPOSITORY TAG IMAGE ID CREATED SIZE wordpress latest ee025cbcbc20 3 days ago 539MB mysql 5.7 1e4405fe1ea9 2 weeks ago 437MB centos latest 0f3e07c0138f 2 months ago 220MB 
[root@localhost ~] REPOSITORY TAG IMAGE ID CREATED SIZE wordpress latest ee025cbcbc20 3 days ago 539MB mysql 5.7 1e4405fe1ea9 2 weeks ago 437MB centos latest 0f3e07c0138f 2 months ago 220MB

二、准备epel YUM源

<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> 7.repo <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo docker-ce.repo
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> 7.repo <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo docker-ce.repo 
[root@localhost ~] 7.repo [root@localhost ~] CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo docker-ce.repo

准备pip工具,用于批量管理python语言开发的工具包(和GitHub二进制的区别主要在于版本)

<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span>
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> 
[root@localhost ~]

由于有安装依赖,建议把下面所有软件包安装后,再安装docker-compose

<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span>
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> 
[root@localhost ~]

三、更新pip版本

<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span>
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> 
[root@localhost ~]

四、切换国内源

<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span>
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> 
[root@localhost ~] [root@localhost ~] [root@localhost ~] [root@localhost ~] [root@localhost ~] [root@localhost ~]

五、安装docker-compose

<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span>
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> 
[root@localhost ~]

六、验证是否安装成功

<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> docker-compose version 1.25.0, build b42d419 docker-py version: 4.1.0 CPython version: 2.7.5 OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> docker-compose version 1.25.0, build b42d419 docker-py version: 4.1.0 CPython version: 2.7.5 OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017 
[root@localhost ~] docker-compose version 1.25.0, build b42d419 docker-py version: 4.1.0 CPython version: 2.7.5 OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017

七、准备容器镜像文件

<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> REPOSITORY TAG IMAGE ID CREATED SIZE wordpress latest ee025cbcbc20 3 days ago 539MB mysql 5.7 1e4405fe1ea9 2 weeks ago 437MB
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> REPOSITORY TAG IMAGE ID CREATED SIZE wordpress latest ee025cbcbc20 3 days ago 539MB mysql 5.7 1e4405fe1ea9 2 weeks ago 437MB 
[root@localhost ~] REPOSITORY TAG IMAGE ID CREATED SIZE wordpress latest ee025cbcbc20 3 days ago 539MB mysql 5.7 1e4405fe1ea9 2 weeks ago 437MB

八、创建目录文件

<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span>
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> <span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span> 
[root@localhost ~] [root@localhost ~]

九、编写docker-compose.yaml文件:
注意该文件的格式 严格注意空格

<span class="token punctuation">[</span>root@localhost wordpressproject<span class="token punctuation">]</span> ```powershell version: <span class="token string">'3'</span> services: db: image: mysql:5.7 volumes: - <span class="token string">"./data:/var/lib/mysql"</span> restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress expose: - 3306 wordpress: depends_on: - db image: wordpress:latest links: - db ports: - <span class="token string">"8080:80"</span> restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress
<span class="token punctuation">[</span>root@localhost wordpressproject<span class="token punctuation">]</span> ```powershell version: <span class="token string">'3'</span> services: db: image: mysql:5.7 volumes: - <span class="token string">"./data:/var/lib/mysql"</span> restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress expose: - 3306 wordpress: depends_on: - db image: wordpress:latest links: - db ports: - <span class="token string">"8080:80"</span> restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress 
[root@localhost wordpressproject] ```powershell version: '3' services: db: image: mysql:5.7 volumes: - "./data:/var/lib/mysql" restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress expose: - 3306 wordpress: depends_on: - db image: wordpress:latest links: - db ports: - "8080:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress

上边的代码很重要尤其是缩进问题一定处理好
十、开启ip转发功能(非常重要)

<span class="token namespace">[root@localhost wordpressproject]</span> <span class="token namespace">[root@localhost wordpressproject]</span> <span class="token namespace">[root@localhost wordpressproject]</span>
<span class="token namespace">[root@localhost wordpressproject]</span> <span class="token namespace">[root@localhost wordpressproject]</span> <span class="token namespace">[root@localhost wordpressproject]</span> 
[root@localhost wordpressproject] [root@localhost wordpressproject] [root@localhost wordpressproject]

十一、立即生效 这部分是帮助的命令 下边才是具体的启动命令
docker-compose相关命令:
如何使用docker-compose

<span class="token namespace">[root@localhost wordpressproject]</span> <span class="token namespace">[root@localhost wordpressproject]</span>
<span class="token namespace">[root@localhost wordpressproject]</span> <span class="token namespace">[root@localhost wordpressproject]</span> 
[root@localhost wordpressproject] [root@localhost wordpressproject]

此命令只能在工程目录中使用,用于启动工程

<span class="token namespace">[root@localhost wordpressproject]</span>
<span class="token namespace">[root@localhost wordpressproject]</span> 
[root@localhost wordpressproject]

停止并删除工程已经创建的容器
十二、启动docker-compse:

<span class="token namespace">[root@localhost wordpressproject]</span> Creating network <span class="token string">"wordpressproject_default"</span> with the default driver Creating wordpressproject_db_1 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> done Creating wordpressproject_wordpress_1 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> done <span class="token namespace">[root@localhost ~]</span> CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4cf5f4cee330 wordpress:latest <span class="token string">"docker-entrypoint.s…"</span> About a minute ago Up About a minute 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:8080<span class="token operator">-</span>>80<span class="token operator">/</span>tcp wordpressproject_wordpress_1 4d9cb6aee451 mysql:5<span class="token punctuation">.</span>7 <span class="token string">"docker-entrypoint.s…"</span> About a minute ago Up About a minute 3306<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 33060<span class="token operator">/</span>tcp wordpressproject_db_1 <span class="token namespace">[root@localhost ~]</span> anaconda<span class="token operator">-</span>ks<span class="token punctuation">.</span>cfg mysql<span class="token punctuation">.</span>tar wordpressproject wordpress<span class="token punctuation">.</span>tar <span class="token namespace">[root@localhost ~]</span> <span class="token namespace">[root@localhost wordpressproject]</span> <span class="token keyword">data</span> docker<span class="token operator">-</span>compose<span class="token punctuation">.</span>yaml <span class="token namespace">[root@localhost wordpressproject]</span> auto<span class="token punctuation">.</span>cnf client<span class="token operator">-</span>key<span class="token punctuation">.</span>pem ib_logfile1 private_key<span class="token punctuation">.</span>pem sys ca<span class="token operator">-</span>key<span class="token punctuation">.</span>pem ib_buffer_pool ibtmp1 public_key<span class="token punctuation">.</span>pem wordpress ca<span class="token punctuation">.</span>pem ibdata1 mysql server<span class="token operator">-</span>cert<span class="token punctuation">.</span>pem client<span class="token operator">-</span>cert<span class="token punctuation">.</span>pem ib_logfile0 performance_schema server<span class="token operator">-</span>key<span class="token punctuation">.</span>pem <span class="token namespace">[root@localhost wordpressproject]</span> db<span class="token punctuation">.</span>opt
<span class="token namespace">[root@localhost wordpressproject]</span> Creating network <span class="token string">"wordpressproject_default"</span> with the default driver Creating wordpressproject_db_1 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> done Creating wordpressproject_wordpress_1 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> done <span class="token namespace">[root@localhost ~]</span> CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4cf5f4cee330 wordpress:latest <span class="token string">"docker-entrypoint.s…"</span> About a minute ago Up About a minute 0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0:8080<span class="token operator">-</span>>80<span class="token operator">/</span>tcp wordpressproject_wordpress_1 4d9cb6aee451 mysql:5<span class="token punctuation">.</span>7 <span class="token string">"docker-entrypoint.s…"</span> About a minute ago Up About a minute 3306<span class="token operator">/</span>tcp<span class="token punctuation">,</span> 33060<span class="token operator">/</span>tcp wordpressproject_db_1 <span class="token namespace">[root@localhost ~]</span> anaconda<span class="token operator">-</span>ks<span class="token punctuation">.</span>cfg mysql<span class="token punctuation">.</span>tar wordpressproject wordpress<span class="token punctuation">.</span>tar <span class="token namespace">[root@localhost ~]</span> <span class="token namespace">[root@localhost wordpressproject]</span> <span class="token keyword">data</span> docker<span class="token operator">-</span>compose<span class="token punctuation">.</span>yaml <span class="token namespace">[root@localhost wordpressproject]</span> auto<span class="token punctuation">.</span>cnf client<span class="token operator">-</span>key<span class="token punctuation">.</span>pem ib_logfile1 private_key<span class="token punctuation">.</span>pem sys ca<span class="token operator">-</span>key<span class="token punctuation">.</span>pem ib_buffer_pool ibtmp1 public_key<span class="token punctuation">.</span>pem wordpress ca<span class="token punctuation">.</span>pem ibdata1 mysql server<span class="token operator">-</span>cert<span class="token punctuation">.</span>pem client<span class="token operator">-</span>cert<span class="token punctuation">.</span>pem ib_logfile0 performance_schema server<span class="token operator">-</span>key<span class="token punctuation">.</span>pem <span class="token namespace">[root@localhost wordpressproject]</span> db<span class="token punctuation">.</span>opt 
[root@localhost wordpressproject] Creating network "wordpressproject_default" with the default driver Creating wordpressproject_db_1 ... done Creating wordpressproject_wordpress_1 ... done [root@localhost ~] CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4cf5f4cee330 wordpress:latest "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:8080->80/tcp wordpressproject_wordpress_1 4d9cb6aee451 mysql:5.7 "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp wordpressproject_db_1 [root@localhost ~] anaconda-ks.cfg mysql.tar wordpressproject wordpress.tar [root@localhost ~] [root@localhost wordpressproject] data docker-compose.yaml [root@localhost wordpressproject] auto.cnf client-key.pem ib_logfile1 private_key.pem sys ca-key.pem ib_buffer_pool ibtmp1 public_key.pem wordpress ca.pem ibdata1 mysql server-cert.pem client-cert.pem ib_logfile0 performance_schema server-key.pem [root@localhost wordpressproject] db.opt

十三、最后测试效果 省略了中途出现的配置用户名 数据库的截图 大同小异
在这里插入图片描述

原文链接:https://blog.csdn.net/smileui/article/details/108556877?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168623078216800185866810%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168623078216800185866810&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-15-108556877-null-null.268%5Ev1%5Ekoosearch&utm_term=docker%E3%80%81wordpress%E3%80%81wordpress%E5%BB%BA%E7%AB%99%E3%80%81wordpress%E4%B8%BB%E9%A2%98%E3%80%81%E5%AE%B9%E5%99%A8%E9%95%9C%E5%83%8F%E3%80%81

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享