Docker Engine 1.12 can be rightly called ” A Next Generation Docker Clustering & Distributed System”. Though Docker Engine 1.12 Final Release is around corner but the recent RC2 brings lots of improvements and exciting features. One of the major highlight of this release is Docker Swarm Mode which provides powerful yet optional ability to create coordinated groups of decentralized Docker Engines. Swarm Mode combines your engine in swarms of any scale. It’s self-organizing and self-healing. It enables infrastructure-agnostic topology.The newer version democratizes orchestration with out-of-box capabilities for multi-container on multi-host app deployments as shown below:
Built on Engine as a uniform building block for self organizing and healing group of Engines, Docker ensures that orchestration is accessible for every developer and operation user. The new Swarm Mode adopts the de-centralized architecture rather than centralized one (key-value store) as seen in the earlier Swarm releases. Swarm Mode uses the Raft consensus algorithm to perform leader selection, and maintain the cluster’s states.
In Swarm Mode, all Docker Engine will unite into a cluster with management tier. It is basically master – slave system but all Docker Engine will be united and they will maintain a cluster state. Instead of running a single container, you will declare a desired state for your application which means multiple container and then engine themselves will maintain that state. Additionally, a new “docker service” feature has been added under the new release. The “docker service create” is expected to be an evolution of “docker run”. Docker run is imperative command and all it helps you to get container up and running.The new “docker service create” command declare that you have to setup a server which can run one or more containers and those container will run , provided the state you declare for the service will be maintained in Engine / inside the distributed store based on raft consensus protocol.That brings the notion of desired state reconciliation. Whenever any node in the cluster goes down, the swarm itself will recognize that there has been deviation between the desired state and it will bring up new instance to reconstruct the reconciliation. I highly recommend visualizing http://thesecretlivesofdata.com/raft/ to understand what does it mean.
Docker Swarm Node is used for orchestrating distributed systems at any scale. It includes primitives for node discovery, raft-based consensus, task scheduling and much more. Let’s see what features does Docker Swarm Mode adds to Docker Cluster functionality:
Looking at the above features, Docker Swarm mode brings the following benefits :
- Distributed: Swarm Mode uses the Raft Consensus Algorithm in order to coordinate and does not rely on a single point of failure to perform decisions.
- Secure: Node communication and membership within a Swarm are secure out of the box. Swarm Mode uses mutual TLS for node authentication, role authorization and transport encryption, automating both certificate issuance and rotation.
- Simple: Swarm Mode is operationally simple and minimizes infrastructure dependencies. It does not need an external database to operate. It uses internal distributed State store.
Below picture depicts Swarm Mode cluster architecture. Fundamentally its a master and slave architecture. Every node in a swarm is Docker Host running Docker Engine. Some of the node has privilege role called Manager.The manager node participate in “raft consensus” group. As shown below, components in blue color are sharing Internal Distributed State
store of the cluster while the green colored components/boxes are worker Nodes. The worker node receive work instructions from the manager group and this is clearly shown in dash lines.
For operation team, it might be relief-tablet as there is no need of any external key-value store like etcd and consul.Docker Engine 1.12 has internal distributed state store to coordinate and hence no longer single point of failure. Additionally, Docker security is no longer an additional implementation,the secure mode is enabled by default.
Getting started with Docker Engine 1.12
Under this blog post, I will cover the following aspects:
- Initializing the Swarm Mode
- Creating the services and Tasks
- Scaling the Service
- Rolling Updates
- Promoting the node to Manager group
To test drive Docker Mode, I used 4 node cluster in Google Cloud Engine all running the latest stable Ubuntu 16.04 system as shown below:
Setting up docker 1.12-rc2 on all the nodes should be simple enough with the below command:
#curl -fsSL https://test.docker.com/ | sh
Run the below command to initialize Swarm Mode under the master node:
Let’s look at docker info command:
Listing the Docker Swarm Master node:
Let us add the first Swarm agent node(worker node) as shown below:
Let’s go back to Swarm Master Node to see the latest Swarm Mode status:
Similarly, we can add the 2nd Swarm agent node to Swarm Mode list:
Finally, we see all the nodes listed:
Let’s add 3rd Swarm Agent node in the similar fashion as shown above:
Finally, the list of worker and master nodes gets displayed as shown below:
Let’s try creating a single service:
As of now, we dont have any service created. Let’s start creating a service called collab which uses busybox image from Dockerhub and all it does is ping collabnix.com website.
Verifying and inspecting the services is done through the below command:
Quick Look at Scaling !!!
Task is an atomic unit of service.We actually create a task whenever we add a new service. For example, as shown below we created a task called collab.
Let’s scale this service to 5:
Now you can see that the service has been scaled to 5.
Rolling Updates Made Easy
Updating a service is pretty simple. The “docker service update” is feature rich and provides loads of options to play around with the service.
Let’s try updating redis container from 3.0.6 to 3.0.7 with 10s delay and parallelism count of 2.
Wow !!! Rolling updates just went flawless.
Time to promote the Agent Node to Manager Node
Let’s try to promote Swarm Agent Node-1 to Manager group as shown below:
In short, Swarm Mode is definitely a neat and powerful feature which provides an easy way to orchestrate Docker containers and replication of services. In our next post, we will look at how overlay networking works under Swarm Mode.