0. Environment

ServerName description IP
manager0 Swarm primary managers 192.168.33.20
manager1 Swarm secondary managers 192.168.33.21
node0 Swarm node 192.168.33.20
node1 Swarm node 192.168.33.20
consul0 Discovery backend 192.168.33.20

1.Install Engine on each node

1.1 Update the yum packages

1
$ sudo yum update

1.2 Install docker

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

1.3 Configure and start engine swarm nodes on port 2375

1
2
3
4
5
6

# vi /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
# systemctl daemon-reload
# systemctl start docker.service
# systemctl enable docker.service

1.4 Verify that docker engine is installed correctly

1
# docker run hello-world

2. Set up a discovery backend

run on consul0 node :

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

3. Create Swarm cluster

To create the primary manager ; on manager0:

1
# docker run -d -p 4000:4000 swarm manage -H :4000 --replication --advertise 192.168.33.20:4000 consul://192.168.33.30:8500

To create the secondary Swarm manager; on manager1:

1
# docker run -d -p 4000:4000 swarm manage -H :4000 --replication --advertise 192.168.33.21:4000 consul://192.168.33.30:8500

Connect to node0 and node1 in turn and join them to the cluster

on Node0:

1
docker run -d swarm join --advertise=192.168.33.10:2375 consul://192.168.33.30:8500

on Node1

1
docker run -d swarm join --advertise=192.168.33.11:2375 consul://192.168.33.30:8500

4. Communicate with the Swarm

Get information about swarm cluster:

1
$ docker -H :4000 info

Run an application on the Swarm:

1
$ docker -H :4000 run hello-world

Check which Swarm node ran the application:

1
$ docker -H :4000 ps

4.References

https://docs.docker.com/swarm/install-manual/