前提需要聲明版本
這里容器的連接是雙向的
yum install docker-compose -y
[root@master wordpress]# cat docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7
volumes:
- /data/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
volumes:
- /data/web_data:/var/www/html
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
docker-compose up -d #啟動服務(wù)
docker-compose restart db或wordpress(服務(wù)名稱)
服務(wù)之間通過dns解析
root@a7fad202cb7a:/var/www/html# cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0
zabbix/zabbix-server-mysql latest e36e7fa7e11a 3 years ago 106MB
zabbix/zabbix-web-nginx-mysql latest 386dc9afc1c4 3 years ago 174MB
zabbix/zabbix-java-gateway latest 4257519fd740 3 years ago 148MB
[root@master zabbix]# cat docker-compose.yml
version: '3'
services:
mysql-server:
image: mysql:5.7
restart: always
command: --character-set-server=utf8 --collation-server=utf8_bin
environment:
MYSQL_ROOT_PASSWORD: root_pwd
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix_pwd
zabbix-java-gateway:
image: zabbix/zabbix-java-gateway:latest
restart: always
zabbix-server:
depends_on:
- mysql-server
- zabbix-java-gateway
image: zabbix/zabbix-server-mysql:latest
ports:
- "10051:10051"
restart: always
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix_pwd
MYSQL_ROOT_PASSWORD: root_pwd
ZBX_JAVAGATEWAY: zabbix-java-gateway
zabbix-web:
depends_on:
- mysql-server
- zabbix-server
image: zabbix/zabbix-web-nginx-mysql:latest
ports:
- "80:80"
restart: always
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix_pwd
MYSQL_ROOT_PASSWORD: root_pwd