一 准备工作:
-
一台安装了 docker 和 docker-compose 的 Linux 系统机
-
通过 docker pull mysql 和 wordpress
[root@localhost ~]# docker version Client: Version: 18.09.8 API version: 1.39 Go version: go1.10.8 Git commit: 0dd43dd87f Built: Wed Jul 17 17:40:31 2019 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.8 API version: 1.39 (minimum version 1.12) Go version: go1.10.8 Git commit: 0dd43dd Built: Wed Jul 17 17:10:42 2019 OS/Arch: linux/amd64 Experimental: false [root@localhost ~]# [root@localhost ~]# docker-compose -v docker-compose version 1.22.0, build f46880fe [root@localhost ~]# docker pull mysql:5.7 [root@localhost ~]# [root@localhost ~]# docker pull wordpress:5.4 [root@localhost ~]# [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql 5.7 ef08065b0a30 2 weeks ago 448MB wordpress 5.4 2da59c54a06a 7 weeks ago 543MB [root@localhost ~]#
二 通过 docker-compose 启动和配置 mysql 和 wordpress 容器
在 /usr/local/docker/wordpress目录内编辑 docker-compose.yml
备注:( 没有目录就新建 )
version: '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:5.4
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: {}
三 通过 ip + 8000端口 就可以访问了
参考文章:
https://www.cnblogs.com/zouzou-busy/p/12149374.html