Clustering of Docker Containers using Docker Swarm

Docker Swarm:

Docker Swarm is native clustering for Docker, which combines a group of Docker Containing hosts  to form a Cluster. In this Tutorial we will form a Three Node cluster, a Master and agent node. This will contain 3 steps.

  1. Set up Nodes
  2. Setup up a Discovery Method.
  3. Forming Cluster.

Setup Nodes for Swarm:

Upgrade Packages all system packages with

sudo apt-get update && sudo apt-get -y upgrade

Install Docker on all nodes.

curl -sSL https://get.docker.com/ | sh

Stop Docker and run it to listen on a port so swarm can connect

sudo service docker stop
sudo docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

After Installing Docker engines and set it to listen on port 2375, we now have to setup a discovery backend that can form a cluster

Setting a Discovery Backend for Clustering: 

Discovery backend helps in identifying and grouping the clusters. There are multiple backend discovery services available like

  • Consul
  • Etcd
  • ZooKeeper
  • libkv
  • staticfile on master

In this tutorial we will use consul as Discovery Service.

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

Forming a Cluster:

On Manager Run this command 

docker run -d -p 4000:4000 swarm manage -H :4000 --replication --advertise <manager0_ip>:4000 consul://<consul_ip>:8500

run docker ps to see if swarm container is running.

On Agent Nodes run the following command to join the cluster.

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

Your cluster is now formed.

From Manager node run this commands:

docker -H :4000 run -itd ubuntu

docker -H :4000 info 

You can see that ubuntu is launched in one of the agent nodes which denotes a successful Cluster.

Posted On 26 May 2016 By MicroPyramid


Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Configuring WordPress Blog as sub-directory alongside Django in Nginx

Using regular expressions within Nginx we can bind urls to particular application servers, below we will configure wordpress blog and django site to be deployed ...

Continue Reading...
How to deploy django with uwsgi and nginx using Ansible play book.

Ansible is a scripting language mostly used to automate installing applications, deploying apps etc..
Why Ansible:
You may think why learn new language if I ...

Continue Reading...
Django Testing Automated with Self Hosted Gitlab CI and Docker

It is a bit pricy if you want to host code for collaboration using bitbucket or github on your own VPS or On-Premisis servers. Gitlab ...

Continue Reading...
open source packages

Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
* We don't provide your email contact details to any third parties