Docker swarm is (aka Docker engine in swarm mode) a native clustering solution that makes a group of Docker hosts into a single logical virtual server. Swarm ensures availability and high performance of your application by distributing it over the number of Docker hosts inside a cluster.

Also, with Docker swarm, you can scale your application horizontally, i.e., increasing number of container instance for the same application.

Our Infrastructure

Install and Configure Docker Swarm on CentOS 7 – Swarm Infrastructure

For the demonstration, I’m using mixed operating system environment:

HostName

IP Address

Operating System

Purpose

dockerm.itgeek.local

192.168.12.10

CentOS 7

Acts as a Docker manager who manages Docker engine running on nodes. Docker manager will also take a part of a cluster ie, It will run containers as well.

node1.itzgeek.local

192.168.12.20

Ubuntu 16.04

Worker Node 1 (Running Docker engine)

node2.itzgeek.local

192.168.12.30

Fedora 26/25

Worker Node 2 (Running Docker engine)

Docker swarm was previously a separate tool. It is now integrated with Docker engine from v 1.12. So, you can just install Docker engine on all of your hosts (Manager and Worker Nodes).

Restart the Docker engine after you have opened up the required ports as the firewall chain does affect the docker rules.

systemctl restart docker

Here onwards, all the commands mentioned are universal docker commands so you can execute the command on any operating system that Docker supports (In our case, CentOS 7, Ubuntu 16.04, and Fedora 26/25).

Create a Swarm

Let’s initiate a cluster creation using “swarm init“. Run the following command on your manager node (dockerm.itzgeek.local).

[root@dockerm ~]# docker swarm init --advertise-addr 192.168.12.10

–advertise-addr option specifies the manager node to publish its address as 192.168.12.10 so that worker node can join the cluster.

Output:

Swarm initialized: current node (uhh38rpazd5tnzjph2g5rhgxy) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \ --token SWMTKN-1-5y1u36a0osykywxeme2akpjp4jgx2l67mbqbc4fnazs39bp314-e6djx8ma2qnevolztpplkn26j \ 192.168.12.10:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.