docker_practice/compose/wordpress.md

52 lines
1.4 KiB
Go
Raw Normal View History

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
[`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:8.0
command:
- --default_authentication_plugin=mysql_native_password
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
2017-11-23 07:48:52 +00:00
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:
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` 安装界面了