## 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 ```sh docker service create --name vote schoolofdevops/vote ``` ```sh docker service ls docker service inspect ``` ``` docker service update --publish-add 80:5000 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 ``` ## Creating Docker Stack Definition 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 ```