Docker Swarm

Docker Swarm provides clustering functionality for Docker Containers, which turns a group of Docker engines into a single virtual Docker engine.

Docker Swarm is an open-source container orchestration platform. It is the native orchestration tool by Docker. There are other orchesteration tools like Kubernetes from Google and Mesos from Apache.

A swarm consists of multiple Docker hosts which run in swarm mode and act as managers and workers. A given Docker host can be a manager, a worker, or perform both roles.

A node is an instance of the Docker engine participating in the swarm.

The following topics follows this tutorial

Create a Swarm

create a swarm. Current node will become a manager

1
2
3
4
5
6
7
8
9
10
$ docker swarm init --advertise-addr 192.168.99.100
Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager.

To add a worker to this swarm, run the following command:

docker swarm join \
--token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
192.168.99.100:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

use docker node ls to view information about the nodes

Add Node to Swarm

Workers can join a swarm using docker swarm join command

1
2
3
4
5
$ docker swarm join \
--token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
192.168.99.100:2377

This node joined a swarm as a worker.

Leave a Swarm

Workers can leave a swarm by executing command docker swarm leave

1
docker swarm leave 

Deploy a Service to the Swarm

1
2
3
$ docker service create --replicas 1 --name helloworld alpine ping docker.com

9uk4639qpg7npwf3fn2aasksr

use docker service ls to see list of running services

Scale the Service

1
2
3
$ docker service scale helloworld=5

helloworld scaled to 5

Remove the Service

1
2
3
$ docker service rm helloworld

helloworld

Reference