Docker Swarm in 5min

Docker deamon and client both need to be atleast versio 1.24+

docker version

Init swarm machne

docker swarm init --advertise-addr <Host_IP>

Join a worker

docker swarm join --token :2377

Join a manager

docker swarm join --manager --token --listen-addr :2377 :2377

To check the machines

docker node ls

Primary / Secondary Managers

  • REQUEST always goes to primary manager always, if the request goes to secondary manager then it is proxied to the primary one.
  • Primary manager will deligate the request to the different workers

Key Concepts of Docker Swarm

  • Manager are need to be odd in number, so that you can solve the split brain problem of the network
  • All masters configured using Raft Consensus Group
  • All workers communicates through the Gossip Network

Create the Service

docker service create --replicas 3 --name job jboss/wildfly

Node Failure,

if the service goes down or container goes off, this this replicas check failes the

desired(3 replicas) !== actual(one failed and 2 runningg)

Then docker reconciles the replicas to 3.

Container failure

Same as the the node failure to fire up the new container

Scale

docker service scale web=6

Global Service

  • One instance of service running at each node(docker swarm machine) of the cluster with the mode as global.

docker service create --mode=global --replicas 3 --name job jboss/wildfly

  • when weexecute this command it fires up the command on each node of the cluster, downloads the image and creates the service at each node of the cluster

Docker Stack

The docker stack deploy command supports compose file version 3.0 and above.

Create a compose file of all services say stack.yml

Run all services

docker stack deploy --compose-file stack.yml

Verify

docker stack ls

View the list of services running

docker service ls

Remove the stack

docker stack rm