2017-11-23 07:48:52 +00:00
|
|
|
|
## 使用 WordPress
|
2016-11-25 14:24:48 +00:00
|
|
|
|
|
2019-03-08 04:21:07 +00:00
|
|
|
|
> 本小节内容适合 `PHP` 开发人员阅读。
|
2015-01-14 06:09:38 +00:00
|
|
|
|
|
2017-11-26 01:54:04 +00:00
|
|
|
|
`Compose` 可以很便捷的让 `Wordpress` 运行在一个独立的环境中。
|
2017-10-31 16:20:30 +00:00
|
|
|
|
|
2017-11-23 07:48:52 +00:00
|
|
|
|
### 创建空文件夹
|
2015-01-14 06:09:38 +00:00
|
|
|
|
|
2017-11-23 07:48:52 +00:00
|
|
|
|
假设新建一个名为 `wordpress` 的文件夹,然后进入这个文件夹。
|
2015-01-14 06:09:38 +00:00
|
|
|
|
|
2017-11-23 07:48:52 +00:00
|
|
|
|
### 创建 `docker-compose.yml` 文件
|
2015-01-14 06:09:38 +00:00
|
|
|
|
|
2018-08-25 14:20:04 +00:00
|
|
|
|
[`docker-compose.yml`](https://github.com/yeasy/docker_practice/blob/master/compose/demo/wordpress/docker-compose.yml) 文件将开启一个 `wordpress` 服务和一个独立的 `MySQL` 实例:
|
2015-01-14 06:09:38 +00:00
|
|
|
|
|
2017-10-31 16:20:30 +00:00
|
|
|
|
```yaml
|
|
|
|
|
version: "3"
|
|
|
|
|
services:
|
|
|
|
|
|
2017-11-23 07:48:52 +00:00
|
|
|
|
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
|
|
|
|
|
volumes:
|
2018-08-25 14:20:04 +00:00
|
|
|
|
db_data:
|
2015-01-14 06:09:38 +00:00
|
|
|
|
```
|
|
|
|
|
|
2017-11-23 07:48:52 +00:00
|
|
|
|
### 构建并运行项目
|
2015-01-14 06:09:38 +00:00
|
|
|
|
|
2017-11-26 01:54:04 +00:00
|
|
|
|
运行 `docker-compose up -d` Compose 就会拉取镜像再创建我们所需要的镜像,然后启动 `wordpress` 和数据库容器。 接着浏览器访问 `127.0.0.1:8000` 端口就能看到 `WordPress` 安装界面了。
|