Ajeet Raina Docker Captain, ARM Innovator & Docker Bangalore Community Leader.

Getting Started with Docker Swarm

4 min read

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 !!!


Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Docker Captain, ARM Innovator & Docker Bangalore Community Leader.

32 Replies to “Getting Started with Docker Swarm”

  1. 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

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

  3. 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.

  4. 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!

  5. 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

  6. 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.

  7. 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!

  8. 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.

  9. 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.

  10. 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.

  11. 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!|

  12. 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.|

  13. 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..

  14. 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.|

  15. 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!

  16. 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

  17. 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!

  18. Any port in a storm Link to proverb.
    Old soldiers never die, they simply fade away. Link to proverb.
    Cowards may die many times before their death.
    First come, first served.
    There’s none so blind as those who will not see.
    An army marches on its stomach.
    You can’t have your cake and eat it too.

Leave a Reply

Your email address will not be published.