作者:NANA-LS | 来源:互联网 | 2023-09-24 03:39
新建一个文件夹,如test,在test文件夹下创建docker-compose.yaml文件,内容如下
version: "3"
services:zabbix-mysql:image: mysql/mysql-server:5.7.22container_name: zabbix-mysqlports:- '3306:3306'environment:- MYSQL_ROOT_PASSWORD="123456"- MYSQL_USER=root- MYSQL_PASSWORD="123456"- MYSQL_DATABASE=zabbixvolumes:- /etc/localtime:/etc/localtime:ro- /etc/timezone:/etc/timezone:ro- ./var/lib/mysql:/var/lib/mysql:rw- ./etc/mysql/my.cnf:/etc/mysql/my.cnf:rwhealthcheck:test: ["CMD", "curl", "-f", "http://localhost"]interval: 10stimeout: 5sretries: 3networks:network_zabbix:ipv4_address: 192.168.137.136ulimits:nproc: 65535nofile:soft: 20000hard: 40000deploy:resources:limits:cpus: '0.70'memory: 1Greservations:cpus: '0.5'memory: 512Mzabbix-web-apache-mysql:image: zabbix/zabbix-web-apache-mysql:centos-latestcontainer_name: zabbix-web-apache-mysqlenvironment:- DB_SERVER_HOST=zabbix-mysql- MYSQL_USER=root- MYSQL_PASSWORD="123456"- ZBX_SERVER_HOST=zabbix-server-mysql- PHP_TZ=Asia/Shanghaivolumes:- /etc/localtime:/etc/localtime:ro- /etc/timezone:/etc/timezone:roports:- '80:80'- '443:443'links:- zabbix-mysql- zabbix-server-mysqldepends_on:- zabbix-mysqlhealthcheck:test: ["CMD", "curl", "-f", "http://localhost"]interval: 10stimeout: 5sretries: 3networks:network_zabbix:ipv4_address: 192.168.137.108zabbix-server-mysql:image: zabbix/zabbix-server-mysql:centos-latestcontainer_name: zabbix-server-mysqlvolumes:- /etc/localtime:/etc/localtime:ro- /etc/timezone:/etc/timezone:ro
# - ./etc/zabbix/zabbix_server.conf:/etc/zabbix/zabbix_server.conf:rw
# - ./usr/local/etc/zabbix_server.conf.d/:/usr/local/etc/zabbix_server.conf.d/:rw- ./usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts:rw- ./usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:rw- ./var/lib/zabbix/modules:/var/lib/zabbix/modules:rw- ./var/lib/zabbix/enc:/var/lib/zabbix/enc:rw- ./var/lib/zabbix/ssl/keys:/var/lib/zabbix/ssl/keys:rw- ./var/lib/zabbix/ssl/certs:/var/lib/zabbix/ssl/certs:rw- ./var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:rw- ./var/lib/zabbix/ssl/ssl_ca:/var/lib/zabbix/ssl/ssl_ca:rw- ./var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:rw- ./var/lib/zabbix/mibs:/var/lib/zabbix/mibs:rwenvironment:- DB_SERVER_HOST=zabbix-mysql- MYSQL_USER=root- MYSQL_PASSWORD="123456"ports:- '10051:10051'links:- zabbix-mysqldepends_on:- zabbix-mysqlhealthcheck:test: ["CMD", "curl", "-f", "http://localhost"]interval: 10stimeout: 5sretries: 3networks:network_zabbix:ipv4_address: 192.168.137.128networks:network_zabbix:driver: bridgeipam:driver: defaultconfig:- subnet: 192.168.137.0/24
注意:挂载卷时如果挂载文件,宿主机上该文件必须存在,否则会出现挂载目录到文件的错误,报错参考
在test文件夹下执行
docker-compose -f docker-compose.yaml up -d
会创建一个自定义网络test_network_zabbix,命名是由本文件夹名_配置文件中定义的网络名构成,如test文件夹名称_network_zabbix
查看网络信息
docker network inspect 4f2fef1e7986
[root@centos71 test]# docker network ls
NETWORK ID NAME DRIVER SCOPE
9022957e163c bridge bridge local
0ae43293d71a composetest_default bridge local
2a00755fdc04 host host local
383bd73d91f0 my_wordpress_default bridge local
92a0641630fa none null local
4f2fef1e7986 test_network_zabbix bridge local
d1c5d7a56e30 zabbix_default bridge local
[root@centos71 test]# docker network inspect 4f2fef1e7986
[{"Name": "test_network_zabbix","Id": "4f2fef1e7986ac138a66cf4c123683eb59957509f64e93903787955c288471a5","Created": "2018-07-27T17:27:15.030268946+08:00","Scope": "local","Driver": "bridge","EnableIPv6": false,"IPAM": {"Driver": "default","Options": null,"Config": [{"Subnet": "192.168.137.0/24"}]},"Internal": false,"Attachable": true,"Ingress": false,"ConfigFrom": {"Network": ""},"ConfigOnly": false,"Containers": {"01fbff5d386b55f91a1e3520d9ad1de9e2dbbe24b71ebcf88e7ef4a0723915d6": {"Name": "zabbix-web-apache-mysql","EndpointID": "677a93dba03836f9465e35d7485d47bd99be8b52e46a6e3f7d2f8e1130d9a83a","MacAddress": "02:42:c0:a8:89:6c","IPv4Address": "192.168.137.108/24","IPv6Address": ""},"9f2aff9c2cfc4f0a5f86fac68214add5882bc7ec399d46223bb4b24f409695e3": {"Name": "zabbix-server-mysql","EndpointID": "da68eed9ff6bdd8b7c801f0ab4350c2269722f2bb711bfcbebc52be12ae105dd","MacAddress": "02:42:c0:a8:89:80","IPv4Address": "192.168.137.128/24","IPv6Address": ""},"cef181055e5ec85dbda0c28562da73a5bd30284b745644af2f6c010af38f9018": {"Name": "zabbix-mysql","EndpointID": "8b454794bdee22800c14659a6e882fff67469786a60239501090761fdad30aa7","MacAddress": "02:42:c0:a8:89:88","IPv4Address": "192.168.137.136/24","IPv6Address": ""}},"Options": {},"Labels": {"com.docker.compose.network": "network_zabbix","com.docker.compose.project": "test","com.docker.compose.version": "1.22.0"}}
]
[root@centos71 test]#
查看容器运行状态
[root@centos71 test]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
01fbff5d386b zabbix/zabbix-web-apache-mysql:centos-latest "docker-entrypoint.sh" 14 minutes ago Up 14 minutes (healthy) 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp zabbix-web-apache-mysql
9f2aff9c2cfc zabbix/zabbix-server-mysql:centos-latest "docker-entrypoint.sh" 14 minutes ago Up 14 minutes (unhealthy) 0.0.0.0:10051->10051/tcp zabbix-server-mysql
cef181055e5e mysql/mysql-server:5.7.22 "/entrypoint.sh mysq…" 14 minutes ago Up 14 minutes (unhealthy) 0.0.0.0:3306->3306/tcp, 33060/tcp zabbix-mysql