赞
踩
参考上一篇博客 版本对应。https://blog.csdn.net/yilvqingtai/article/details/118796925
配置文件配置项总览:
- version: "3.9"
- services:
- my_name: //自定义服务名称
- build:
- context: . //(1)可以dockerfile所在路径,也可以是git的url (2)相对路径,相对于当前配至文件目录
- dockerfile: Dockerfile //默认Dockerfile,此处可以自己指定某路径下的dockerfile文件
- args: //自定义参数kv,运行该文件的时候,参数可以被dockeefile文件引用,详见说明
- labels: //给镜像打标签,V3.3以上,官方建议格式:反向dns:业务名(如:com.baidu.text:accountapp)
- network: //V3.4以上,构建容器时,指派当前的网络环境组,如果none 表示禁用网络
- shm_size: 2gb 或者 1000000000 //为此构建的容器设置/dev/shm分区的大小/dev/shm可自行百度
- target: prod //V3.4以上,在内部定义构建指定的阶段dockerfile
- cap_add:
- cap_drop:
- cgroup_parent:
- command: //覆盖默认命令,和dockerfile指令相似.
- configs:
- container_name: //指定自定义容器的名称;Docker容器名称必须是唯一的,如果指定了自定义名称,则无法将服务扩展到多个容器.
- credential_spec: //v3.3
- depends_on: //服务依赖关系
- deploy: //指定与部署和运行服务相关的配置
- endpoint_mode: //为连接到群集的外部客户端指定服务发现方法
- labels: //指定服务的标签。这些标签仅在服务上设置,而不在服务的任何容器上设置。
- mode: //全局或复制(副本容器)
- placement: //指定约束和首选项的位置
- max_replicas_per_node:
- replicas: //如果复制了服务,请指定在任何给定时间应运行的容器数。
- resources: //配置资源限制.
- restart_policy: //配置是否以及如何在容器退出时重新启动容器
- rollback_config: //配置在更新失败的情况下应如何回滚服务
- update_config: //配置服务应如何更新。用于配置滚动更新.
- devices:
- dns: //自定义dns服务
- dns_search: //自定义DNS搜索域
- entrypoint: //覆盖默认entrypoint
- env_file: //从文件添加环境变量
- environment: //添加环境变量。您可以使用数组或字典。任何布尔值; true,false,yes no,需要用引号括起来
- expose:
- external_links:
- extra_hosts:
- healthcheck:
- image:
- init:
- isolation:
- labels:
- links:
- logging:
- network_mode:
- networks:
- pid:
- ports:
- profiles:
- restart:
- secrets:
- security_opt:
- stop_grace_period:
- stop_signal:
- sysctls:
- tmpfs:
- ulimits:
- userns_mode:
- volumes:
- driver:
- driver_opts:
- external:
- name:
- version: "3.7" #版本
- services: #服务
- nginx: #服务名称
- build: ./dir #指定构建目录
- image: nginx:tag #指定基础镜像
- build:
- context: ./dir
- build:
- context: .
- dockerfile: Dockerfile-alternate
- ARG buildno
- ARG gitcommithash
- build:
- context: .
- args:
- buildno: 1
注意: 在Dockerfile中,如果在FROM指令之前指定ARG,则在FROM下的构建指令中不能使用ARG。
YAML布尔值(true,false,yes,no,on,off)必须用引号括起来,以便解析器将它们解释为字符串。
- build:
- context: .
- cache_from:
- - alpine:latest
- - corp/web_app:3.14
- build:
- context: .
- labels:
- com.example.description: "Accounting webapp"
/dev/shm
分区的大小- build:
- context: .
- shm_size: '2gb'
- build:
- context: .
- target: prod
- cap_add:
- - ALL
-
- cap_drop:
- - NET_ADMIN
- - SYS_ADMIN
cgroup_parent: m-executor-abcd
command: ["bundle", "exec", "thin", "-p", "3000"]
/ <config_name>
中。源名称和目标安装点都设置为配置名称. 支持3.3版本以上.- version: "3.7"
- services:
- redis:
- image: redis:latest
- deploy:
- replicas: 1
- configs:
- - my_config
- - my_other_config
- configs:
- my_config:
- file: ./my_config.txt
- my_other_config:
- external: true
source
: Docker中存在的配置名称target
: 要在服务的任务容器中装入的文件的路径和名称。默认为:/<source>
uid和gid
: 在服务的任务容器中拥有已装入的配置文件的数字UID或GID.默认为0.mode
: 以八进制表示法在服务的任务容器中装入的文件的权限。默认值为0444.配置无法写入,因为它们安装在临时文件系统中,因此如果设置了可写位,则会将其忽略。可以设置可执行位。- version: "3.7"
- services:
- redis:
- image: redis:latest
- deploy:
- replicas: 1
- configs:
- - source: my_config
- target: /redis_config
- uid: '103'
- gid: '103'
- mode: 0440
- configs:
- my_config:
- file: ./my_config.txt
- my_other_config:
- external: true
container_name: nginx-test
- version: "3.8"
- services:
- myservice:
- image: myimage:latest
- credential_spec:
- config: my_credential_spec
-
- configs:
- my_credentials_spec:
- file: ./my-credential-spec.json|
docker-compose up
: 以依赖顺序启动服务.docker-compose up SERVICE
: 自动包含SERVICE的依赖项.docker-compose stop
: 按依赖顺序停止服务.- version: "3.7"
- services:
- web:
- build: .
- depends_on:
- - db
- - redis
- redis:
- image: redis
- db:
- image: postgres
- version: "3.7"
- services:
- redis:
- image: redis:alpine
- deploy:
- replicas: 6
- update_config:
- parallelism: 2
- delay: 10s
- restart_policy:
- condition: on-failure
endpoint_mode: vip
: Docker为服务分配虚拟IP(VIP),作为客户端到达网络服务的前端。 Docker在客户端和服务的可用工作节点之间路由请求,而无需客户端知道有多少节点参与服务或其IP地址或端口。endpoint_mode: dnsrr
: DNS循环(DNSRR)服务发现不使用单个虚拟IP。 Docker为服务设置DNS条目,以便服务名称的DNS查询返回IP地址列表,客户端直接连接到其中一个。- version: "3.7"
-
- services:
- wordpress:
- image: wordpress
- ports:
- - "8080:80"
- networks:
- - overlay
- deploy:
- mode: replicated
- replicas: 2
- endpoint_mode: vip
-
- mysql:
- image: mysql
- volumes:
- - db-data:/var/lib/mysql/data
- networks:
- - overlay
- deploy:
- mode: replicated
- replicas: 2
- endpoint_mode: dnsrr
-
- volumes:
- db-data:
-
- networks:
- overlay:
- version: "3.7"
- services:
- web:
- image: web
- deploy:
- labels:
- com.example.description: "This label will appear on the web service"
- version: "3.7"
- services:
- worker:
- image: dockersamples/examplevotingapp_worker
- deploy:
- mode: global
- version: "3.7"
- services:
- db:
- image: postgres
- deploy:
- placement:
- constraints:
- - node.role == manager
- - engine.labels.operatingsystem == ubuntu 14.04
- preferences:
- - spread: node.labels.zone
- version: "3.7"
- services:
- worker:
- image: dockersamples/examplevotingapp_worker
- networks:
- - frontend
- - backend
- deploy:
- mode: replicated
- replicas: 6
- version: "3.7"
- services:
- redis:
- image: redis:alpine
- deploy:
- resources:
- limits:
- cpus: '0.50'
- memory: 50M
- reservations:
- cpus: '0.25'
- memory: 20M
none
,on-failure
,any- version: "3.7"
- services:
- redis:
- image: redis:alpine
- deploy:
- restart_policy:
- condition: on-failure
- delay: 5s
- max_attempts: 3
- window: 120s
continue或者pause
ns|us|ms|s|m|h
parallelism
:一次更新的容器数delay
: 更新一组容器之间的等待时间.continue,rollback,pause
.默认pause.(ns|us|ms|s|m|h)
- version: "3.7"
- services:
- vote:
- image: dockersamples/examplevotingapp_vote:before
- depends_on:
- - redis
- deploy:
- replicas: 2
- update_config:
- parallelism: 2
- delay: 10s
- order: stop-first
- dns:
- - 8.8.8.8
- - 9.9.9.9
- dns_search:
- - dc1.example.com
- - dc2.example.com
entrypoint: /code/entrypoint.sh
- env_file:
- - ./common.env
- - ./apps/web.env
- - /opt/secrets.env
VAR = VAL
格式。以#开头的行被视为注释并被忽略。空行也被忽略。- environment:
- RACK_ENV: development
- SHOW: 'true'
- SESSION_SECRET:
- expose:
- - "3000"
- - "8000"
- external_links:
- - redis_1
- - project_db_1:mysql
- - project_db_1:postgresql
- extra_hosts:
- - "somehost:162.242.195.82"
- - "otherhost:50.31.209.229"
- 162.242.195.82 somehost
- 50.31.209.229 otherhost
- healthcheck:
- test: ["CMD", "curl", "-f", "http://localhost"]
- interval: 1m30s
- timeout: 10s
- retries: 3
- start_period: 40s
- test: ["CMD", "curl", "-f", "http://localhost"]
- test: ["CMD-SHELL", "curl -f http://localhost || exit 1"]
- test: curl -f https://localhost || exit 1
- healthcheck:
- disable: true
- version: "3.7"
- services:
- web:
- image: alpine:latest
- init: true
- web:
- links:
- - db
- - db:database
- - redis
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。