安装docker-compose
[root@service ~]# systemctl stop firewalld
[root@service ~]# setenforce 0
[root@service ~]# systemctl start docker
[root@service ~]# wget https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64
创建目录
[root@service composetest]# mkdir test
[root@service composetest]# cd test/
[root@service test]# vim docker-compose.yml
编写docker-compose.yml文件
version: '3'
networks:
mynetwork:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.18.0.0/24
services:
db:
image: mysql:5.7
container_name: mysql57
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
command:
--character-set-server=utf8
--collation-server=utf8_general_ci
volumes:
- db_data:/var/lib/mysql
networks:
mynetwork:
ipv4_address: 172.18.0.10
wordpress:
depends_on:
- db
image: wordpress:latest
container_name: wordpress
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
- wp_data:/var/www/html
networks:
mynetwork:
ipv4_address: 172.18.0.11
ports:
- 88:80
discuz:
depends_on:
- db
image: tencentci/discuz
container_name: discuz
restart: always
environment:
DISCUZ_DB_HOST: db:3306
volumes:
- discuz_data:/var/www/html
networks:
mynetwork:
ipv4_address: 172.18.0.12
ports:
- 80:80
adminer:
depends_on:
- db
image: adminer
container_name: adminer
restart: always
networks:
mynetwork:
ipv4_address: 172.18.0.15
ports:
- 8080:8080
volumes:
db_data:
wp_data:
discuz_data:
启动编排镜像
[root@service test]# docker-compose up
[+] Running 8/8
⠿ Network test_mynetwork Created 0.1s
⠿ Volume "test_wp_data" Created 0.0s
⠿ Volume "test_discuz_data" Created 0.0s
⠿ Volume "test_db_data" Created 0.0s
⠿ Container mysql57 Created 0.0s
⠿ Container adminer Created 0.0s
⠿ Container wordpress Created 0.1s
⠿ Container discuz Created
通过主机IP地址访问Discuz论坛搭建网站
通过主机IP地址8080端口访问数据库管理界面