# 方式一
代码语言:javascript复制[root@localhost wwwroot]# docker pull wordpress
[root@localhost wwwroot]# docker pull mysql:5.6
[root@localhost wwwroot]# docker run -d --name wordpress-mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 mysql:5.6
[root@localhost wwwroot]# docker run -d --name wordpress-wordpress --link wordpress-mysql:mysql -p 80:80 wordpress
# 方式二
代码语言:javascript复制创建 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: {}
docker-compose -f docker-compose.wordpress.yml up -d #后台运行
docker-compose -f docker-compose.wordpress.yml down #停止并删除服务