1 root@docker01:~# mkdir my_wordpress
2 root@docker01:~# mkdir /db_data #建立用於存儲MySQL的獨立路徑
1 root@docker01:~# cd my_wordpress/
2 root@docker01:~/my_wordpress# vi docker-compose.yml
3 version: '3.3'
4 services:
5 db:
6 image: mysql:5.7
7 volumes:
8 - /db_data:/var/lib/mysql
9 restart: always
10 environment:
11 MYSQL_ROOT_PASSWORD: somewordpress
12 MYSQL_DATABASE: wordpress
13 MYSQL_USER: wordpress
14 MYSQL_PASSWORD: wordpress
15 wordpress:
16 depends_on:
17 - db
18 image: wordpress:latest
19 ports:
20 - "8000:80"
21 restart: always
22 environment:
23 WORDPRESS_DB_HOST: db:3306
24 WORDPRESS_DB_USER: wordpress
25 WORDPRESS_DB_PASSWORD: wordpress
26
27 volumes:
28 db_data:
1 root@docker01:~/my_wordpress# docker-compose up -d
1 root@docker01:~# docker ps
1 root@docker01:~# docker-compose images
2 root@docker01:~# docker-compose ps