Wordpress+Mysql+nginx反向代理安装
https://hub.docker.com/_/wordpress

步骤1:配置mysql容器

首先创建db目录,下面添加一个mysql容器使用的env.list文件
1
MYSQL_DATABASE=wpdb
2
MYSQL_USER=wpuser
3
MYSQL_PASSWORD=wppass
4
MYSQL_RANDOM_ROOT_PASSWORD=1
Copied!
然后启动mysql容器:
1
docker run --name db -d --net net1 -v $(pwd)/db/data:/var/lib/mysql --env-file ./db/env.list mysql:5.7
Copied!
mysql跑起来了:
1
[email protected]:/simon-testing/wordpress# docker ps -a
2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3
d512e5e68e6e mysql:5.7 "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 3306/tcp, 33060/tcp db
Copied!

步骤2:配置wordpress容器

拉取wordpress镜像,这个镜像里已经自带apache和php7.2:
docker pull wordpress:5-php7.2
创建wp目录,下面添加一个wordpress容器使用的env.list文件,注意WORDPRESS_DB_HOST要与mysql的容器名一致:
1
WORDPRESS_DB_HOST=db
2
WORDPRESS_DB_USER=wpuser
3
WORDPRESS_DB_PASSWORD=wppass
4
WORDPRESS_DB_NAME=wpdb
Copied!
启动wordpress容器,把80端口绑定到宿主机的8080端口上:
1
docker run --name wp -p 8080:80 --net net1 -d --env-file ./wp/env.list wordpress:5-php7.2
Copied!
之后,在其他主机上用浏览器访问宿主机的8080端口,就能看到wordpress的安装引导界面了:

步骤3:配置nginx反向代理容器

创建nginx目录,下面添加一个nginx容器使用的default.conf文件,里面设置反向代理wp容器:
1
server {
2
listen 80;
3
server_name localhost;
4
access_log /var/log/nginx/host.access.log main;
5
location / {
6
#root /usr/share/nginx/html;
7
index index.php index.html index.htm;
8
proxy_pass http://wp/;
9
#Proxy Settings
10
proxy_redirect off;
11
proxy_set_header Host $host;
12
proxy_set_header X-Real-IP $remote_addr;
13
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
14
}
15
error_page 500 502 503 504 /50x.html;
16
location = /50x.html {
17
root /usr/share/nginx/html;
18
}
19
}
Copied!
然后运行nginx容器,link到wp容器,并把宿主机80端口与nginx容器80端口绑定:
1
docker run --name nginx -d -v $(pwd)/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro --link wp --net net1 -p 80:80 nginx:alpine
Copied!
三个容器一起运行中:
1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2
e160335b6070 nginx:alpine "nginx -g 'daemon of…" 56 seconds ago Up 54 seconds 0.0.0.0:80->80/tcp nginx
3
1e0276d9a234 mysql:5.7 "docker-entrypoint.s…" 19 minutes ago Up 19 minutes 3306/tcp, 33060/tcp db
4
80f68202f960 wordpress:5-php7.2 "docker-entrypoint.s…" 25 minutes ago Up 25 minutes 0.0.0.0:8080->80/tcp wp
Copied!
现在访问宿主机,不用添加8080端口也能访问到wordpress了:
Last modified 1yr ago