您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
定义配置文件中的部分(如构建,部署,依赖,网络等)的顶级键与支持它们作为子主题的选项一起列出。这映射到Compose文件的<key>:<option>:<value>
缩进结构
Compose文件是定义services,networks和volumes的YAML文件。 Compose文件的默认路径是./docker-compose.yml。
服务定义包含应用于为该服务启动的每个容器的配置. 类似:
docker container create
docker network create
docker volume create
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
,anyversion: "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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。