用一断时间,记录下使用的规则,因为使用docker-compose作为最后发布容器的配置,所以Dockfile尽量少控制逻辑,大多放于yml中
version: "3.0"
services:
dotnettest:
image: "cc/dotnettest:v3.0.02.bb74344"
container_name: "cc.dotnettest"
network_mode: "host"
user: root
volumes:
- "/publish/conf/config.xml:/publish/config.xml"
- "/publish/conf/log4net.config:/publish/log4net.config"
- "/var/log/dotnettest:/publish/log"
- "/etc/localtime:/etc/localtime"
- "/etc/resolv.conf:/etc/resolv.conf"
logging:
driver: "json-file"
options:
max-size: "50M"
max-file: "10"
restart: "always"
deploy:
resources:
limits:
cpus: "0.50"
memory: 4096M
reservations:
cpus: "0.05"
memory: 500M
environment:
TZ: "Asia/Shanghai"
参数说明:
- network_mode:使用host方式,减少防火墙变动,要重启整个docker的风险
- volumes=》publish:配置文件映射出来用于修改配置
- volumes=》log4net:日志配置文件映射出来用于修改配置
- volumes=》localtime:让容器时区跟随宿主机
- volumes=》resolv:让容器dns跟随宿主机
- logging:限制docker logs的日志
- restart:让故障可自动重启
- deploy:限制使用的资源
- environment:用于数据库驱动需要此变量