docker-compose的一些用法(定义hosts,健康检查,指定MAC地址,时区,特权模式启动)
前言
相关文档:
《docker-compose的yml文件中常用选项》
《docker-compose网络》
《docker-compose限制容器cpu和内存》
《docker-compose的build使用》
1. 定义 hosts
version: '3.7'
services:
minio1:
image: harbocto.xxx.com.cn/public/minio:RELEASE.2021-02-01T22-56-52Z
……
extra_hosts:
- "minio1:10.10.xxx.125"
- "minio2:10.10.xxx.126"
- "minio3:10.10.xxx.127"
- "minio4:10.10.xxx.131"
2. 健康检查
version: '3.7'
services:
minio1:
image: harbocto.xxx.com.cn/public/minio:RELEASE.2021-02-01T22-56-52Z
……
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
3. 指定MAC地址
- 语法
mac_address: MAC地址
- 示例
version: "3.1"
services:
coreservice:
container_name: core-service-003
image: java
ports:
- 8030:8000
- 8031:8001
- 8032:8002
mac_address: 00:16:3e:08:9f:8f
volumes:
- /data/coreservice003:/opt/coreservice
command: /opt/coreservice/start.sh
4. 指定时区
4.1 方法一:变量指定
注意
: 本方法是否生效
要看镜像是否支持以变量指定时区
- 语法
environment:
TZ: Asia/Shanghai
- 示例
version: "3.1"
services:
mysql:
image: harbocto.boe.com.cn/public/mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: xxxxxxx
MYSQL_DATABASE: devops
TZ: Asia/Shanghai
restart: always
ports:
- 3306:3306
volumes:
- ./data:/var/lib/mysql
4.2 方法二:挂载时区文件
- 方法
/usr/share/zoneinfo/Asia/Shanghai 将载到镜像中 /etc/localtime 或 /usr/share/zoneinfo/Asia/Shanghai
volumes:
- /usr/share/zoneinfo/Asia/Shanghai:/usr/share/zoneinfo/Asia/Shanghai:ro
- 示例
version: "3.1"
services:
mysql:
image: harbocto.boe.com.cn/public/mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: xxxxxx
MYSQL_DATABASE: devops
TZ: Asia/Shanghai
restart: always
ports:
- 3306:3306
volumes:
- ./data:/var/lib/mysql
- /usr/share/zoneinfo/Asia/Shanghai:/usr/share/zoneinfo/Asia/Shanghai:ro
5. 特权模式
privileged: true
- 示例
version: "3.1"
services:
emqx:
image: "emqx/emqx:4.3.11"
container_name: "iot-emqx"
privileged: true
environment:
posted on 2021-12-21 20:13 运维开发玄德公 阅读(107) 评论(0) 编辑 收藏 举报 来源