Docker Swarm – Native Clustering for Docker Hosts

Docker swarm provides native clustering for docker hosts. In other words it turns a pool of docker hosts into a single virtual host. Conceptually a swarm cluster looks like the following:


How to get swarm ?
Option-1: Use swarm container image from docker hub (docker pull swarm)
Option-2: Build from source. If you plan to use swarm on non-Intel platforms eg. Power, then you need to build swarm from source. With Ubuntu Vivid LE for PowerPC architecture having docker and associated Go build tools (gccgo), you can compile swarm from source and use the same to create swarm clusters for docker on OpenPower servers. Just follow the instructions mentioned in github.

Here are the steps that I usually follow for working with swarm on my Power servers running Ubuntu Vivid LE

$ mkdir ~/go.prj
$ export GOPATH=~/go.prj
$ export PATH=$PATH:~/go.prj/bin
$ go get
$ go get
$ cd $GOPATH/src/
$ godep go install .

swarm binary will be available under $GOPATH/bin/

Getting started
1. For each docker host that needs to be part of swarm cluster
Configure docker daemon to expose docker API over TCP

   docker -H tcp:// -d

2. Run swarm and register the host
If using the swarm docker image

   docker run -H tcp:// -d swarm join --addr=<node_ip:2375> <discovery-option>

If using the swarm built from source

   swarm join --addr=<node_ip:2375> <discovery-option>

3. Start the swarm manage service on the designated machine
If using the swarm docker image

   docker run -d -p <swarm_cluster_mgr_port>:2375 swarm manage <discovery-option>

If using the swarm built from source

   swarm manage <discovery-option>

Discovery and cluster membership
Swarm supports multiple mechanisms for discovering of swarm nodes and creating cluster.
1. Hosted Discovery
Use token://cluster_id as the discovery-option
Hosted at
2. File
Add docker hosts in <ip>:<port> format to a file
Use file://path_to_file as the discovery-option
3. Comma separated list of node’s details (<ip>:<port>) directly in the CLI
4. Etcd
Use etcd://<etcd_ip>/<path> as the discovery-option
5. Consul
Use consul://<consul_ip>/<path> as the discovery-option
6. Zookeeper
Use zk://<zookeeper_addr1>,<zookeeper_addr2>/<path> as the discovery-option

A complete example using the Hosted discovery option with swarm docker image.

Swarm Manager

$sudo docker run --rm swarm create


$sudo docker -H tcp:// run -d swarm join --addr= token://747fb4e15d1c948922f9b71ef9e9d12b


$sudo docker -H tcp:// run -d swarm join --addr= token://747fb4e15d1c948922f9b71ef9e9d12b

Swarm Manager

$sudo docker run -d -p 2375:2375 swarm manage token://747fb4e15d1c948922f9b71ef9e9d12b
$sudo docker -H tcp:// info
Containers: 5
Strategy: spread
Filters: affinity, health, constraint, port, dependency
Nodes: 2
└ Containers: 2
└ Reserved CPUs: 0 / 1
└ Reserved Memory: 0 B / 513.9 MiB
└ Containers: 3
└ Reserved CPUs: 0 / 1
└ Reserved Memory: 0 B / 513.9 MiB

Hope this will help you to get started with docker swarm. I also plan to write some more articles on swarm, especially on swarm scheduling and placement. Till then happy swarming 😉

Pradipta Kumar Banerjee

I'm a Cloud and Linux/ OpenSource enthusiast, with 16 years of industry experience at IBM. You can find more details about me here - Linkedin

You may also like...