Spread the love


Docker Swarm is 1 year old now. Docker Inc. during DockerConEU, December 2014 made the announcement of Docker Swarm. A Docker Swarm is a clustering manager for Docker and Docker Machine, a CLI tool for provisioning Docker hosts. Docker Inc. intented to provide a complete and integrated solution for running containers and not allowing themselves to be restricted to only providing the Docker engine.

Docker Swarm is the native clustering tool for Docker. Swarm uses the standard Docker API, i.e., containers can be launched using normal docker run commands and Swarm will take care of selecting an appropriate host to run the container on. What it actually means that the other tools that use the Docker API—such as Compose and bespoke scripts—can use Swarm without any changes and take advantage of running on a cluster rather than a single host.



The basic architecture of Swarm is fairly straightforward:

i. Each host runs a Swarm agent and one host runs a Swarm manager (on small test clusters this host may also run an agent).

ii. The manager is responsible for the orchestration and scheduling of containers on the hosts.

ii. Swarm can be run in a high-availability mode where etcd,Consul, or ZooKeeper is used to handle failover to a back-up manager.

There are several different methods for how hosts are found and added to a cluster, which is known as discovery in Swarm. By default, token-based discovery is used, where the addresses of hosts are kept in a list stored on the Docker Hub.



Let’ start with practical implementation of Docker Swarm. I quickly turned on 4 node cluster on my Google Cloud Engine, 1 Swarm Master Node, 2 Agent Nodes and 1 Swarm Manager Node to manage the overall cluster. Here is my environment details:




Setting up Swarm Master Node:

Ensure that Docker 1.9.1 is installed on all the nodes of Docker swarm cluster. You can follow the below command to update all the Docker Hosts to the latest version:

wget -qO- https://get.docker.com/ | sh
[Remember its capital-O and not zero]

Processing triggers for systemd (225-1ubuntu9) …
Processing triggers for man-db (2.7.4-1) …
Setting up docker-engine (1.9.1-0~wily) …
Installing new version of config file /etc/bash_completion.d/docker …
Installing new version of config file /etc/init.d/docker …
Installing new version of config file /etc/init/docker.conf …
Processing triggers for ureadahead (0.100.0-19) …
Processing triggers for systemd (225-1ubuntu9) …
+ sh -c docker version
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:20:08 UTC 2015
OS/Arch: linux/amd64
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:20:08 UTC 2015
OS/Arch: linux/amd64
If you would like to use Docker as a non-root user, you should now consider
adding your user to the “docker” group with something like:
sudo usermod -aG docker your-user
Remember that you will have to log out and back in for this to take effect!

Starting Docker Daemon

root@dockerhost-1 ~]# docker -H tcp:// -d &
[1] 11516
[root@dockerhost-1 ~]# Warning: ‘-d’ is deprecated, it will be removed soon. See usage.
WARN[0000] please use ‘docker daemon’ instead.
INFO[0000] Listening for HTTP on tcp (
ERRO[0000] WARNING: No –storage-opt dm.thinpooldev specified, using loopback; this configuration is strongly disco
uraged for production use
INFO[0000] [graphdriver] using prior storage driver “devicemapper”
INFO[0000] Option DefaultDriver: bridge
INFO[0000] Option DefaultNetwork: bridge
WARN[0000] Running modprobe bridge nf_nat br_netfilter failed with message: modprobe: WARNING: Module br_netfilter
not found.
, error: exit status 1
INFO[0000] Firewalld running: true
INFO[0000] Loading containers: start.
INFO[0000] Loading containers: done.
INFO[0000] Daemon has completed initialization
INFO[0000] Docker daemon commit=a01dc02/1.8.2 execdriver=native-0.2 graphdriver=dev
icemapper version=1.8.2-el7.centos
[root@dockerhost-1 ~]#

Setting up Docker Swarm:

root@docker-1:~# docker run –rm swarm create

It created a token ID which is a heart of Docker Swarm cluster configuration.

Setting up Swarm Agent Node 1:[]

Ensure that Docker 1.9.x is installed on Agent Node 1. Also, docker daemon need to be running following the similar steps during the master node setup.

#docker run -d swarm join –addr= token://7733f838d176809cb2f2d24eb34ce78c


Setting up Swarm Manager Node :[]

root@docker-3:~# docker run -d -p 7000:2375 swarm manage token://7733f838d176809cb2f2d24eb34ce78c

Please remember that 7000 is swarm manager port which is being set.

Now you can see the swarm cluster details:

root@docker-3:~# docker -H tcp:// info
Containers: 0
Images: 2
Storage Driver:
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 1
+ Status: Healthy
+ Containers: 0
+ Reserved CPUs: 0 / 1
+ Reserved Memory: 0 B / 3.794 GiB
+ Labels: executiondriver=native-0.2, kernelversion=4.2.0-18-generic, operatingsystem=Ubuntu 15.10, storagedriver
Execution Driver:
Kernel Version:
Operating System:
CPUs: 1
Total Memory: 3.794 GiB
Name: b26a2bbb336e
Http Proxy:
Https Proxy:
No Proxy:

As just one node has been added to the cluster node, it shows just Node-1 added to the swarm cluster.

Setting up Swarm Agent Node 2 :[]

root@docker-2:~# docker run -d swarm join –addr= token://7733f838d176809cb2f2d24eb34ce78c

Finally, you can list out all the nodes added to the swarm cluster  by running the below command on Swarm Manager node as shown:
#docker run –rm swarm list token://7733f838d176809cb2f2d24eb34ce78c

Wow !!! Here you go…Your Multi-Node Swarm Cluster is Ready to rock !!!

Let’s create a container and run it through swarm Manager:

sudo docker -H tcp:// run -dt –name swarm-test nginx /bin/sh

root@docker-1:~# docker images
INFO[0999] GET /v1.18/images/json
INFO[0999] +job images()
INFO[0999] -job images() = OK (0)
nginx latest 813e3731b203 4 days ago 133.8
centos latest 14dab3d40372 5 days ago 194.7
swarm latest e9ff33e7e5b9 11 days ago 17.15
ajeetraina/dell-syscfg v1.0 d121b6e6dba4 12 weeks ago 1.449
tduzan/docker-omsa latest ffcbdafb4aa6 16 months ago 806.4

Lets see what containers are running on each swarm agent machines:

root@docker-3:~# docker -H tcp:// ps
d0ee6dad4b39 nginx:latest “/bin/sh” 58 minutes ago Up 58 minutes 80/tcp,
443/tcp docker-1/swarm-test
cd9bc8c96e45 ajeetraina/dell-syscfg:v1.0 “/bin/bash” About an hour ago Up About an hour
d0bcc8da090e bad926a6fb50:latest “/bin/bash” About an hour ago Up About an hour

What it means? Sitting on Swarm Manager Node you can simply create containers and interestingly you don’t need to worry about what node shall this container sit on. Your Swarm Cluster is intelligent enough to take care of right resource for your container. Happy Swarming !!!



Spread the love
Categories: Docker

Ajeet Raina

My name is Ajeet Singh Raina and I am an author of this blogging site. I am a Docker Captain, ARM Innovator & Docker Bangalore Community Leader. I bagged 2 special awards last year(2019): Firstly, “The Tip of Captain’s Hat Award” at Dockercon 2019, San Francisco, and secondly, “2019 Docker Community Award“. I run Collabnix Community Slack with over 5300+ audience . I have built popular GITHUB repositories like DockerLabs, KubeLabs, Kubetools, RedisPlanet Terraform etc. with the support of Collabnix Community. Currently working as Developer Relations Manager at Redis Labs where I help customers and community members adopt Redis. With over 12,000+ followers over LinkedIn & close to 5100+ twitter followers, I like sharing Docker and Kubernetes related content . You can follow me on Twitter(@ajeetsraina) & GitHub(@ajeetraina)


SeetTek · 31st May 2016 at 4:53 pm

I am typically to running a blog and i actually appreciate your content. The article has actually peaks my interest. I am going to bookmark your website and keep checking for brand spanking new information. http://eurobetsonline24.ru

SeetTek · 5th June 2016 at 2:47 am

This really answered my problem, thanks! http://teleslots24.ru

SeetTek · 7th June 2016 at 4:33 pm

Aw, this was a very nice post. In concept I wish to put in writing like this moreover – taking time and actual effort to make an excellent article… but what can I say… I procrastinate alot and under no circumstances appear to get something done. http://happyslots2016.ru

SeetTek · 8th June 2016 at 3:30 pm

Good day! I simply want to give a huge thumbs up for the good information you will have here on this post. I shall be coming back to your blog for more soon. http://happyslots2016.ru

SeetTek · 10th June 2016 at 4:10 pm

Spot on with this write-up, I really assume this web site wants rather more consideration. I’ll in all probability be once more to read way more, thanks for that info. http://magicslots2016.ru

hero · 15th July 2016 at 8:49 am

If you desire to increase your knowledge only keep visiting this website and
be updated with the latest news update posted here.

BlaineVGhosn · 23rd July 2016 at 10:14 pm

Hello! Someone inside my Myspace group shared this website
around so I got to give it a look. I’m definitely loving the
info. I’m bookmarking and are tweeting this to my followers!

Outstanding blog and wonderful design.

CherZForcier · 26th July 2016 at 3:21 am

Very nice post. I just discovered your blog and
wanted to mention that I’ve truly loved browsing your blog posts.
Whatever the case I am going to be subscribing on the feed and
I am hoping you write once more immediately!

RanaWBiskach · 27th July 2016 at 7:34 am

I do believe all the concepts you’ve offered within your post.

They’re very convincing and will certainly work. Nonetheless, the posts are too
brief for starters. May just you please prolong
them a little from subsequent time? Thanks to the

HaroldORisse · 27th July 2016 at 10:31 pm

Im not that much of a online reader actually yet
your sites really nice, ensure that it stays up! I’ll go ahead and bookmark your
site to return in the foreseeable future.

EddieXSuthar · 28th July 2016 at 12:24 am

WOW just what I was searching for. Came here by searching for

DarellUOrdon · 1st August 2016 at 1:03 am

All things are very open with a precise clarification of your challenges.
It absolutely was definitely informative. Your internet
site is extremely helpful. Many thanks for sharing!

ElinorWMedel · 11th August 2016 at 8:25 pm

This web site was… how can i say it? Relevant!! Finally I
have found a thing that helped me. Cheers!

MarvinJYeary · 20th August 2016 at 5:03 am

whoah this weblog is excellent i like studying your posts.
Keep up the great work! You understand, many people are hunting around for this info,
you could aid them greatly.

RenaeLOrtaga · 1st September 2016 at 6:33 pm

Hi there, I really like reading most of your article.

I wanted to create a bit comment to support you.

HerthaEMuney · 3rd September 2016 at 1:57 am

Hey very interesting blog!

MartinJDebey · 5th September 2016 at 12:29 am

Very quickly this web site will be famous among all blogging viewers, as a result of it’s fastidious articles or reviews

IsraelZKhang · 10th September 2016 at 5:41 am

Pretty portion of content. I just stumbled upon your blog and in accession capital to claim that I
get actually loved account your blog posts. Any way
I’ll be subscribing on your augment or even I achievement you get
right of entry to persistently fast.

RisaBJoshlin · 25th September 2016 at 6:53 pm

I am sure this article has touched all of
the internet visitors, its really really nice piece of writing on strengthening
new blog.

SethYMahan · 4th October 2016 at 11:11 pm

Howdy! I understand this is kind of off-topic but I needed to ask.
Does running a well-established blog like yours require a massive amount work?
I’m completely new to writing a blog however I do
write in my diary on a daily basis. I’d like to start a blog so
I can easily share my own experience and feelings online. Please let me know if you have any
suggestions or tips for brand new aspiring blog owners.

Scottie Grisanti · 10th October 2016 at 10:18 pm

This is the perfect website for anyone who hopes to understand this topic. You realize a whole lot its almost hard to argue with you (not that I personally will need to…HaHa). You certainly put a new spin on a topic which has been written about for decades. Great stuff, just great!|

Rosamond Mallis · 11th October 2016 at 1:02 pm

Thank you for some other informative site. Where else may just I get that type of info written in such an ideal method? I’ve a project that I’m simply now operating on, and I have been at the glance out for such information.|

VernonUClear · 13th October 2016 at 11:49 am

I am extremely impressed together with your writing abilities and also with all
the structure in your weblog. Is this a paid theme or have you modify it yourself?
In any case keep the excellent premium quality writing, it can be uncommon to search a
nice blog similar to this one nowadays..

Phyllis Cost · 13th October 2016 at 7:21 pm

Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a bit, but instead of that, this is wonderful blog. A fantastic read. I will definitely be back.|

Moira Eddins · 10th November 2016 at 1:24 am

Fantastic website you have here but I was wanting to know if you knew of any user discussion forums that cover the same topics discussed in this article? I’d really like to be a part of community where I can get feedback from other experienced people that share the same interest. If you have any suggestions, please let me know. Many thanks!

    ajeetraina · 28th December 2016 at 11:16 am

    You can join Docker community slack channel for discussion on this blog.

financial news · 15th November 2016 at 8:37 pm

Nice blog right here! Additionally your site so much up fast! What web host are you the use of? Can I get your affiliate link to your host? I want my website loaded up as fast as yours lol

RobertHMckey · 16th November 2016 at 5:19 am

It’s a pity you don’t use a donate button! I’d certainly donate to the
brilliant blog! I suppose for now i’ll accept book-marking and adding your RSS feed to my Google account.
I look forward to completely new updates and definately will
talk about this site with my Facebook group. Talk soon!

    ajeetraina · 28th December 2016 at 11:15 am

    I have added donation button now. Feel free to contribute. Thanks.

NanMCzerkies · 18th November 2016 at 11:14 am

This piece of writing provides clear idea designed for the new people of blogging, that the truth is how to
do managing a blog.

Leave a Reply

Your email address will not be published. Required fields are marked *

Join Collabnix SlackIt's 100% FREE!

Get chance to chat with 5500+ DevOps Engineers !