Docker-compose combat Wordpress
1. Create a file
mkdir wordpress
cd wordpress
vim Docker-compose.yml
2. Write Docker-compose.yml file:
reads as follows:
version: "3"
services:
db:
image: 10.30.12.55/docker/mysql:5.6
volumes:
- /var/lib/mysql:/var/lib/mysql
#自动重启
restart: always
environment:
#指定MySQL的root账号初始密码
MYSQL_ROOT_PASSWORD: 123456
#指定容器启动后要创建的数据库
MYSQL_DATABASE: wordpress
#指定容器在启动后要创建的普通用户账号,该账号有远程登录的权限
MYSQL_USER: tom
#为用户设置密码
MYSQL_PASSWORD: 123456
wordpress:
depends_on:
- db
image: 10.30.12.55/docker/wordpress
ports:
- "8000:80"
restart: always
environment:
#指定要使用的数据库名
WORDPRESS_DB_NAME: wordpress
#指定要MySQL容器的ip和端口
WORDPRESS_DB_HOST: db:3306
#指定登录MySQL的账号
WORDPRESS_DB_USER: tom
#指定登录MySQL的密码
WORDPRESS_DB_PASSWORD: 123456
Build and run the project
docker-compose up -d
Compose will pull the mirror and then create a mirrored what we need, and then start the wordpress database container.
Then browser to access the ip:8000
port will be able to see the WordPress installation interface.