Skip to content

Instantly share code, notes, and snippets.

@christianbriggs
Forked from initcron/swarm_tutorial_v3.md
Created November 28, 2017 21:12
Show Gist options
  • Save christianbriggs/0a08e7058459c08b9d7dba6ef4e91f1d to your computer and use it in GitHub Desktop.
Save christianbriggs/0a08e7058459c08b9d7dba6ef4e91f1d to your computer and use it in GitHub Desktop.
Docker Swarm with V3 stack specifications and stack deploy

Lab : Orchestrating and deploying app in Production with SWARM

Deploying Application Stack with Swarm Mode and Stack version "3" specification

Launch a Visualizer on Master (SWARM Manager)

docker run -itd -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock schoolofdevops/visualizer

Find out the IP address of the node which would be designated as master

ifconfig 

or 

ip addr 

Note down the IP address, lets call it as IPADDR

Setup Swarm Cluster

On the master node, initialize swarm


docker swarm init --advertise-addr _IPADDR_

Note down the command sequence to join swarm node, and execute it on all the other nodes which will form this swarm cluster. Verify the swarm is created by checking the visualizer.

To recall join tokens for worker nodes, you could use

docker swarm join-token worker

[Sample Output]

docker swarm join \
    --token SWMTKN-1-07fyl870ztlnrk8i2d58jn1igtrldahiwb2o6plf87dasa34dq-4ej0sofwoy4e62vgu6rvpcfys \
    138.197.71.9:2377

Deploying Service with swarm - The imperative way

docker service create --name vote schoolofdevops/vote
docker service ls 
docker service inspect 
docker service  update --publish-add 80:80 vote

Try accessing port 80 on any of the nodes in the swarm cluster to validate.

Scaling a service

docker service scale vote=4
docker service  ls
docker service scale vote=2

Adding service to a overlay network

docker network ls
docker network create --driver overlay custom-01
docker network ls 

docker service  update --network-add custom-01 vote
docker network inspect custom-01

Cleaning Up

docker service rm vote 

Orchestrating Applications with Stack Deploy

Copy compose file v3 into docker stack file

cp docker-compose-v3.yml docker-stack.yml

Edit docker-stack.yml and update network driver from bridge to overlay

Deploy a stack

docker stack deploy --compose-file docker-stack.yml voting 

Validate

docker stack ls

docker stack services voting

docker service ls 

docker service scale voting_vote=4

Creating Deploy Specs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment