通过docker compose安装Wordpress
根据上一个测试的环境,使用docker compose实现一个命令安装完成wordpress+mysql+nginx反向代理

单机编排测试1:

首先把前一个实验的三个容器全部删除(如果服务器上还有其他容器要保留,不要使用以下命令):
1
docker stop $(docker ps -q)
2
docker rm $(docker ps -aq)
Copied!
然后创建一个docker-compose.yaml文件:
1
version: '3'
2
3
services:
4
5
db:
6
image: mysql:5.7
7
volumes:
8
- ./db/data/:/var/lib/mysql/
9
env_file:
10
- ./db/env.list
11
networks:
12
webnet:
13
aliases:
14
- "mysql"
15
expose:
16
- "3306"
17
18
wp:
19
image: wordpress:5-php7.2
20
env_file:
21
- ./wp/env.list
22
networks:
23
webnet:
24
aliases:
25
- "wordpress"
26
expose:
27
- "80"
28
ports:
29
- "8080:80"
30
depends_on:
31
- db
32
33
nginx:
34
image: nginx:alpine
35
volumes:
36
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
37
networks:
38
webnet:
39
aliases:
40
- "www"
41
expose:
42
- "80"
43
ports:
44
- "80:80"
45
depends_on:
46
- db
47
- wp
48
49
networks:
50
webnet: {}
Copied!
安装命令工具:apt install docker-compose
然后使用docker-compose up命令运行起来
1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2
ea683c8ec5dc nginx:alpine "nginx -g 'daemon of…" 47 seconds ago Up 46 seconds 0.0.0.0:80->80/tcp wordpress_nginx_1
3
9267439c0a0e wordpress:5-php7.2 "docker-entrypoint.s…" 48 seconds ago Up 47 seconds 0.0.0.0:8080->80/tcp wordpress_wp_1
4
2aba0bad886d mysql:5.7 "docker-entrypoint.s…" 48 seconds ago Up 48 seconds 3306/tcp, 33060/tcp wordpress_db_1
Copied!
如果要使容器在后台运行,只需要像docker run一样添加 -d参数即可。
停止并删除容器:docker-compose down
停止但不删除容器:docker-compose stop
恢复容器运行:docker-compose start

单机编排测试2:

使用本地域名和ip地址来编排容器,docker-compose.yaml文件修改如下:
1
version: '3'
2
3
services:
4
5
db:
6
image: mysql:5.7
7
container_name: db.maxidea.com
8
volumes:
9
- ./db/data/:/var/lib/mysql/
10
env_file:
11
- ./db/env.list
12
networks:
13
net2:
14
ipv4_address: 10.10.1.101
15
expose:
16
- "3306"
17
18
wp:
19
image: wordpress:5-php7.2
20
container_name: wp.maxidea.com
21
env_file:
22
- ./wp/env.list
23
networks:
24
net2:
25
ipv4_address: 10.10.1.102
26
expose:
27
- "80"
28
ports:
29
- "8080:80"
30
extra_hosts:
31
- "db.maxidea.com:10.10.1.101"
32
- "nx.maxidea.com:10.10.1.103"
33
34
nginx:
35
image: nginx:alpine
36
container_name: nx.maxidea.com
37
volumes:
38
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
39
networks:
40
net2:
41
ipv4_address: 10.10.1.103
42
expose:
43
- "80"
44
ports:
45
- "80:80"
46
extra_hosts:
47
- "db.maxidea.com:10.10.1.101"
48
- "wp.maxidea.com:10.10.1.102"
49
50
networks:
51
net2:
52
ipam:
53
driver: default
54
config:
55
- subnet: "10.10.1.0/24"
Copied!
运行效果:
1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2
f869d6d5818f nginx:alpine "nginx -g 'daemon of…" 13 seconds ago Up 11 seconds 0.0.0.0:80->80/tcp nx.maxidea.com
3
d1e1e39b51db mysql:5.7 "docker-entrypoint.s…" 13 seconds ago Up 11 seconds 3306/tcp, 33060/tcp db.maxidea.com
4
faf42ab22d04 wordpress:5-php7.2 "docker-entrypoint.s…" 13 seconds ago Up 12 seconds 0.0.0.0:8080->80/tcp wp.maxidea.com
Copied!
Last modified 1yr ago