image 定义了我们将会用到哪一个 servicedepends_on 让我们指定在某个 service 部署以后,该 service 才部署。这里是在 redis 部署之后,vote service 才开始部署 deploy 则指定了集群部署(swarm deployment)
- vote:
- image: dockersamples/examplevotingapp_vote:before
- ports:
- - 5000:80
- networks:
- - frontend
- depends_on:
- - redis
- deploy:
- replicas: 2
- update_config:
- parallelism: 2
- restart_policy:
- condition: on-failure
- version: "3"
- services:
- redis:
- image: redis:alpine
- ports:
- - "6379"
- networks:
- - frontend
- deploy:
- replicas: 2
- update_config:
- parallelism: 2
- delay: 10s
- restart_policy:
- condition: on-failure
- db:
- image: postgres:9.4
- volumes:
- - db-data:/var/lib/postgresql/data
- networks:
- - backend
- deploy:
- placement:
- constraints: [node.role == manager]
- vote:
- image: dockersamples/examplevotingapp_vote:before
- ports:
- - 5000:80
- networks:
- - frontend
- depends_on:
- - redis
- deploy:
- replicas: 2
- update_config:
- parallelism: 2
- restart_policy:
- condition: on-failure
- result:
- image: dockersamples/examplevotingapp_result:before
- ports:
- - 5001:80
- networks:
- - backend
- depends_on:
- - db
- deploy:
- replicas: 2
- update_config:
- parallelism: 2
- delay: 10s
- restart_policy:
- condition: on-failure
- worker:
- image: dockersamples/examplevotingapp_worker
- networks:
- - frontend
- - backend
- deploy:
- mode: replicated
- replicas: 1
- labels: [APP=VOTING]
- restart_policy:
- condition: on-failure
- delay: 10s
- max_attempts: 3
- window: 120s
- visualizer:
- image: dockersamples/visualizer:stable
- ports:
- - "8080:8080"
- stop_grace_period: 1m30s
- volumes:
- - "/var/run/docker.sock:/var/run/docker.sock"
- deploy:
- placement:
- constraints: [node.role == manager]
- networks:
- frontend:
- backend:
- volumes:
- db-data:
是 中的一个新文件类型,只和 Compose Version 3 兼容。
- docker-stack.yml
关键字,允许我们指定一个集群部署(swarm deployment)的各种特性。
比如,voting app 配置中,使用这个关键字,创建了 vote 和 result services 的副本 (每个 service 有两个 container,被部署到 swarm 集群中).
voting app 同样使用
约束某些 services 只能够在 manager node 中执行。
- deploy
- docker-stack.yml 文件来部署系统的命令。
Compose files.
- version: "3" 的
,这之前是在标准 Compose files 中被支持的, 而 Compose file 则是基于 Dockerfile 的。为了使用
- build
,我们需要使用 pre-built image
- docker stack deploy
来运行与 Version 3 兼容的 applications.
- docker compose up
来源: http://www.bubuko.com/infodetail-1949129.html