本文最后更新于 319 天前,其中的信息可能已经过时,如有错误请发送邮件到wuxianglongblog@163.com
docker单机版的容器编排工具docker-compose基本使用
一.docker-compose概述
1.什么是docker-compose
所谓的容器编排工具,指的是批量管理一组容器的方法。
目前比较主流的单机编排工具自然是"docker-compose",其可以描述docker如何启动一组容器。
关于compose文件编写规范可参考GitHub链接哟:
https://github.com/compose-spec/compose-spec/blob/master/spec.md
2.安装docker-compose
(1)需要先安装epel环境
[root@docker201.oldboyedu.com ~]# yum -y install epel-release
(2)安装docker-compose
[root@docker201.oldboyedu.com ~]# yum -y install docker-compose
二.docker-compose常用命令总结
推荐阅读:
https://docs.docker.com/compose/gettingstarted/
https://docs.docker.com/compose/compose-file/compose-file-v3/
https://docs.docker.com/compose/compose-file/compose-file-v2/
三.docker-compose案例-zabbix5.4
1.编写zabbix的docker-compose.yml 配置文件
cat > docker-compose.yml <<EOF
version: '3'
services:
mysql-server:
image: mysql:8.0
restart: always
environment:
MYSQL_ROOT_PASSWORD: root_pwd
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix_pwd
networks:
- zabbix-net
command: ["--character-set-server=utf8", "--collation-server=utf8_bin", "--default-authentication-plugin=mysql_native_password"]
zabbix-java-gateway:
image: zabbix/zabbix-java-gateway:alpine-5.4-latest
restart: always
networks:
- zabbix-net
zabbix-server:
depends_on:
- mysql-server
image: zabbix/zabbix-server-mysql:alpine-5.4-latest
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
networks:
- zabbix-net
ports:
- "10051:10051"
zabbix-web-nginx-mysql:
depends_on:
- zabbix-server
image: zabbix/zabbix-web-nginx-mysql:alpine-5.4-latest
ports:
- "80:8080"
restart: always
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix_pwd
MYSQL_ROOT_PASSWORD: root_pwd
networks:
- zabbix-net
networks:
zabbix-net:
EOF
2.使用docker-compose工具管理zabbix容器
docker-compose up:
创建容器并启动.
docker-compose down:
停止并删除容器.
docker-compose up -d :
创建容器并后台启动
docker-compose start:
容器全部启动
docker-compose stop zabbix-server:
仅启动abbix-server服务对应的容器.
docker-compose stop:
容器全部停止
docker-compose stop zabbix-server:
仅停止zabbix-server服务对应的容器.
docker-compose restart
容器全部重启.
docker-compose scale zabbix-java-gateway=3 # 要注意端口冲突的问题,指定的services不应该有ports属性.
温馨提示:
其他帮助信息请直接参考:"docker-compose --help"。