安装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: bridgeipam:driver: defaultconfig:- subnet: 172.18.0.0/24services:db:image: mysql:5.7container_name: mysql57restart: alwaysenvironment:MYSQL_ROOT_PASSWORD: 123456MYSQL_DATABASE: wordpressMYSQL_USER: wordpressMYSQL_PASSWORD: wordpresscommand:--character-set-server=utf8--collation-server=utf8_general_civolumes:- db_data:/var/lib/mysqlnetworks:mynetwork:ipv4_address: 172.18.0.10wordpress:depends_on:- dbimage: wordpress:latestcontainer_name: wordpressrestart: alwaysenvironment:WORDPRESS_DB_HOST: db:3306WORDPRESS_DB_USER: wordpressWORDPRESS_DB_PASSWORD: wordpressWORDPRESS_DB_NAME: wordpressvolumes:- wp_data:/var/www/htmlnetworks:mynetwork:ipv4_address: 172.18.0.11ports:- 88:80discuz:depends_on:- dbimage: tencentci/discuzcontainer_name: discuzrestart: alwaysenvironment:DISCUZ_DB_HOST: db:3306volumes:- discuz_data:/var/www/htmlnetworks:mynetwork:ipv4_address: 172.18.0.12ports:- 80:80adminer:depends_on:- db image: adminercontainer_name: adminerrestart: alwaysnetworks:mynetwork:ipv4_address: 172.18.0.15ports:- 8080:8080volumes: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端口访问数据库管理界面