原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢!
原文链接地址:『中级篇』Docker-Stack部署投票应用(50)
之前用docker-compose创建过投票应用,现在通过docker-stack来创建多机的部署。源码:https://github.com/limingios/docker/tree/master/No.5/labs/wordpress
######docker-compose文件
编辑docker-compose文件,从github下载下来。
这个配置文件里面装了一个可视化的配置工具visualizer:stable 可以查看到docker-swarm 所有的节点信息。
cd labs/
cd example-vote-app/
more docker-compose.yml
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: 1
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
placement:
constraints: [node.role == manager]
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:
docker stack deploy example --compose-file=docker-compose.yml
docker stack ls
docker stack services example
PS:docker stack 就介绍到这里吧,其实最关键的是编写docker-compose.yml查看官网的学习方式。对于本次编写的一些关键字建议看看官网学习下。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。