Voting App
Stack file
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:
Output
~> docker stack deploy -c voting-app-stack.yml voteapp
Creating network voteapp_backend
Creating network voteapp_frontend
Creating network voteapp_default
Creating service voteapp_db
Creating service voteapp_vote
Creating service voteapp_result
Creating service voteapp_worker
Creating service voteapp_visualizer
Creating service voteapp_redis
~> docker stack ls
NAME SERVICES
voteapp 6
~> docker stack ps voteapp
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
b1njmmzpgcmm voteapp_redis.1 redis:alpine node1 Running Running 7 seconds ago
x95ey2184xgp voteapp_visualizer.1 dockersamples/visualizer:stable node3 Running Preparing 47 seconds ago
wgf2f30cxi1p voteapp_worker.1 dockersamples/examplevotingapp_worker:latest node1 Running Running 42 seconds ago
swntnndwxd0f voteapp_result.1 dockersamples/examplevotingapp_result:before node2 Running Preparing 57 seconds ago
tewhac0g3cym voteapp_vote.1 dockersamples/examplevotingapp_vote:before node3 Running Running 51 seconds ago
snh51sumot29 voteapp_db.1 postgres:9.4 node2 Running Running about a minute ago
uwje6shq6j12 voteapp_redis.2 redis:alpine node2 Running Preparing 4 seconds ago
wgv95v095ldz voteapp_vote.2 dockersamples/examplevotingapp_vote:before node1 Running Running 51 seconds ago
~> docker stack services voteapp
ID NAME MODE REPLICAS IMAGE PORTS
ggl399dqpbmx voteapp_redis replicated 2/2 redis:alpine *:30000->6379/tcp
r7cdesgag4hv voteapp_visualizer replicated 1/1 dockersamples/visualizer:stable *:8080->8080/tcp
txeqd5tns73f voteapp_db replicated 1/1 postgres:9.4
ua3byn5n29ll voteapp_vote replicated 2/2 dockersamples/examplevotingapp_vote:before *:5000->80/tcp
vuv6bn3gjl12 voteapp_worker replicated 1/1 dockersamples/examplevotingapp_worker:latest
yvxa2jh4nunj voteapp_result replicated 1/1 dockersamples/examplevotingapp_result:before *:5001->80/tcp
~> docker network ls
NETWORK ID NAME DRIVER SCOPE
...
x80wjd8oxu44 voteapp_backend overlay swarm
tgh2s208273i voteapp_default overlay swarm
357oak1kajm9 voteapp_frontend overlay swarm
- One cool feature of Stacks is that we have so called visualizer for free: