Docker 12 comes with swarm mode

One of the more exciting new features of Docker is to create a swarm of docker containers. Using the same docker tools to run a single container you can scale up to run several. I experimented with it a while ago for the ClusterVision Trinity project. I largely followed the steps from the Docker 11 swarm tutorial Build a Swarm cluster for Production. Swarm is much easier to setup and install than Kubernetes.

In Docker 12, swarm has become an integrated part of docker engine. Every docker engine is immediately capable of running swarm. The new features decided to play on docker and swarm's strengths, which is to make it easy to use. So what was easy before is now even easier.

Lets see how that looks in practice. Before docker 12 you would have to run the following:

docker run -d -p 8500:8500 --name=consul progrium/consul -server -bootstrap

docker run -d -p 4000:4000 swarm manage -H :4000 --replication --advertise 172.30.0.161:4000 consul://172.30.0.161:8500

In Docker 12, this becomes

docker swarm init

There is no longer any need to setup a separate DNS server (consul in the example), as Docker now comes with a built-in DNS server for its own services. The swarm init command will also print the follow up commands to join a node. Most importantly it will print the connection secrets that are needed to join the swarm.

The command to join a cluster was:

docker run -d swarm join --advertise=<node_ip>:2375 consul://<consul_ip>:8500

In docker 12, this becomes:

docker swarm join --secret 4ao565v9jsuogtq5t8s379ulb

This can also be copied from the output of docker swarm init. So all in all it is much easier to setup a swarm cluster natively.

Docker 12 also comes with a new method of running containers in a swarm. In earlier versions of swarm, if you wanted to scale up a task to run in multiple containers you had to docker run it against the management node it several times. In the newer Docker 12, a docker service create command is added, which allows you to declare the specifics of the service and not care about how they are executed.

docker service create --name redis --replicas=5 myservice

It is possible scale up and down a service and to provide service tags. It is also possible to run a service globally on all nodes in the cluster.

With swarm in mind, the Dockerfile now contains a new keyword HEALTHCHECK. The healthcheck will be used to verify that your service is still running as it should.

Notably missing from the service definition are a few command line options that are available to docker run. It is not yet possible to define --privileged containers or use --net=host on a service. This makes it impossible to e.g. run kolla inside a docker swarm (which it can in Kubernetes).

So to summarize, the new native swarm interface is a small improvement over the previous version. It will make setting up a docker swarm even easier than before.