# 1.定义项目,切换到该项目目录
# Compose项目目录:可根据需要命名,是应用程序镜像的上下文环境,仅包含用于构建镜像的资源。
[root@hecs-hqs-01 ~]# mkdir my_wordpress && cd my_wordpress
[root@hecs-hqs-01 my_wordpress]#
# 2.创建并编辑docker-compose.yml 的compose文件来定义项目
# db定义的是mysql服务器,wordpress定义了wordpress博客项目,db_data卷用于保存提交到数据库的数据
[root@hecs-hqs-01 my_wordpress]# vi docker-compose.yml
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
# 3.项目目录中执行docker-compose命令构建项目
[root@hecs-hqs-01 my_wordpress]# docker-compose up -d
[+] Running 34/34
⠿ wordpress Pulled 48.6s
⠿ 42c077c10790 Pull complete 24.3s
...略 45.0s
⠿ 39f9aa71aa04 Pull complete 45.1s
⠿ db Pulled 94.3s
⠿ c1ad9731b2c7 Pull complete 46.0s
...略 90.7s
⠿ 1b606c4f93df Pull complete 90.7s
[+] Running 4/4
⠿ Network my_wordpress_default Created 0.1s
⠿ Volume "my_wordpress_db_data" Created 0.0s
⠿ Container my_wordpress-db-1 Started 1.2s
⠿ Container my_wordpress-wordpress-1 Started
# 4.执行命令查看运行中的容器
[root@hecs-hqs-01 my_wordpress]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
49b78626c20c wordpress:latest "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:8000->80/tcp my_wordpress-wordpress-1
fecf57f4dfd8 mysql:5.7 "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp my_wordpress-db-1
# 5.在浏览器访问Wordpress
在浏览器访问:http://192.168.200.103:8000/
注册账号,完成登录后,可以进入wordpress首页。
# 6.关闭和清理
# 执行如下命令删除容器、默认网络、卷
[root@localhost my_wordpress]# docker-compose down --volumes
[+] Running 4/4
⠿ Container my_wordpress-wordpress-1 Removed 1.4s
⠿ Container my_wordpress-db-1 Remov... 1.7s
⠿ Volume my_wordpress_db_data Remov... 0.0s
⠿ Network my_wordpress_default Remo... 0.0s
标签:Compose,root,db,compose,wordpress,WordPress,Docker,my,docker From: https://www.cnblogs.com/caifa/p/17465844.html