用Docker-Compose一分钟搭建Wordpress博客系统
环境:
CentOS 7.5
Docker 20.10.2
Docker-Compose 1.25.5
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@localhost ~]# docker version # Docker版本
Client: Docker Engine - Community
Version: 20.10.2
API version: 1.41
Go version: go1.13.15
Git commit: 2291f61
Built: Mon Dec 28 16:17:48 2020
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.2
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 8891c58
Built: Mon Dec 28 16:16:13 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[root@localhost ~]# docker-compose version # Docker-compose版本
docker-compose version 1.25.5, build 8a1c60f6
docker-py version: 4.1.0
CPython version: 3.7.5
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
参考: Docker-Compose官方搭建Wordpress教程:https://docs.docker.com/compose/wordpress/
1.下载项目(docker-compose.yml)
[root@localhost ~]# cd /home/
[root@localhost home]# mkdir my_wordpress
[root@localhost home]# cd my_wordpress/
[root@localhost my_wordpress]# vim docker-compose.yml
version: '3.3' #compose文件版本
services:
db: # 服务1:db
image: mysql:5.7 # 使用镜像 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: # 服务2:wordpress
depends_on: # wordpress服务启动时依赖db服务,所以会自动先启动db服务
- db
image: wordpress:latest # 使用镜像 wordpress:latest最新版
ports:
- "8000:80" #端口映射8000:80
restart: always
environment: # 环境
WORDPRESS_DB_HOST: db:3306 # wordpress连接db的3306端口
WORDPRESS_DB_USER: wordpress # wordpress的数据库用户为wordpress
WORDPRESS_DB_PASSWORD: wordpress # wordpress的数据库密码是wordpress
WORDPRESS_DB_NAME: wordpress # wordpress的数据库名字是wordpress
volumes:
db_data: {}
说明:
可以看到上面的docker-compose.yml
文件中第一行为version:'3.3'
,这个是compose文件的版本,它是与docker引擎的版本相对应的,并且向下兼容。
2.启动项目
注意:大部分的compose命令都需要到docker-compose.yml文件所在的目录下才能执行。
前台启动项目: docker-compose up
**后台执行该服务可以加上 *-d* 参数:** docker-compose up -d
指定yml文件启动:docker-compose -f 【yml文件绝对路径】 up / -d
[root@localhost my_wordpress]# docker-compose up -d # 后台运行项目
Creating network "my_wordpress_default" with the default driver
-----》# 为wordpress项目创建my_wordpress_default网络
Creating volume "my_wordpress_db_data" with default driver
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
6ec7b7d162b2: Downloading [======================================> ] 20.64MB/27.1MB
fedd960d3481: Download complete
7ab947313861: Download complete
64f92f19e638: Downloading [=============================================> ] 1.278MB/1.419MB
3e80b17bff96: Download complete
014e976799f9: Waiting
59ae84fee1b3: Waiting
7d1da2a18e2e: Waiting
301a28b700b9: Waiting
529dc8dbeaf3: Waiting
bc9d021dc13f: Waiting
529dc8dbeaf3: Pull complete
bc9d021dc13f: Pull complete
Digest: sha256:c3a567d3e3ad8b05dfce401ed08f0f6bf3f3b64cc17694979d5f2e5d78e10173
Status: Downloaded newer image for mysql:5.7
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
6ec7b7d162b2: Already exists
db606474d60c: Pull complete
afb30f0cd8e0: Pull complete
3bb2e8051594: Pull complete
4c761b44e2cc: Pull complete
c2199db96575: Pull complete
1b9a9381eea8: Pull complete
50f0689715a3: Pull complete
8a6cc018dd45: Pull complete
052299cf2d76: Pull complete
ee83da709c88: Pull complete
5b10df91e6d0: Pull complete
a2eb858e27d8: Pull complete
e6269830d5ad: Pull complete
228a0fa8a95f: Pull complete
91f7abe86332: Pull complete
5c3d3e1e4145: Pull complete
e75d27a32f14: Pull complete
3c632295f58e: Pull complete
84352e306791: Pull complete
Digest: sha256:e3a851040e7eef9c2b6dd954bfcf08b5a9847b2efbc252d4ccb1b0864225d9fc
Status: Downloaded newer image for wordpress:latest
Creating my_wordpress_db_1 ... done
Creating my_wordpress_wordpress_1 ... done
Attaching to my_wordpress_db_1, my_wordpress_wordpress_1
db_1 | 2021-01-09 03:56:06+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.32-1debian10 started.
db_1 | 2021-01-09 03:56:06+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1 | 2021-01-09 03:56:06+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.32-1debian10 started.
db_1 | 2021-01-09 03:56:06+00:00 [Note] [Entrypoint]: Initializing database files
db_1 | 2021-01-09T03:56:06.498622Z 0 [Warning] TIMESTAMP