Docker Swarm in 5min
2 min readDec 14, 2017
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 <worker_token> <manager_ip>:2377Join a manager
docker swarm join --manager --token <manager_token> --listen-addr <master2>:2377 <master1>:2377To check the machines
docker node lsPrimary / 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/wildflyNode 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=6Global 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 <stackName>Verify
docker stack lsView the list of services running
docker service lsRemove the stack
docker stack rm <stack_name>