NHAILA Achraf
3 min readSep 2, 2023

Setup Docker Swarm (centos 7)

Image3

Requirements :

  • 1 machine master
  • 2 machines as workers

Presentation

Setup & introduce to the features of Docker Swarm

Plan :

  1. Setup master swarm
  2. Install docker into centos 7
  3. Start Docker
  4. Assign Ip address to the manager swarm
  5. Open protocols and ports between the hosts
  6. init SWARM
  7. Adding nodes to the swarm
  8. Install docker into centos 7
  9. Start Docker
  10. Add a worker to the swarm
  11. Manager “node ls” command to see the worker nodes:

1. Setup master swarm

  1. Install docker for centos 7
$ yum install -y yum-utils
$ yum-config-manager - add-repo https://download.docker.com/linux/centos/docker-ce.repo
$ yum install docker-ce docker-ce-cli containerd.io

b.Start Docker

$ systemctl start docker

c. Assign Ip address to the manager swarm

The ip address of the manager machine (Master :67.205.189.189)

The IP address must be assigned to a network interface available to the host operating system. All nodes in the swarm need to connect to the manager at the IP address.

d. Open protocols and ports between the hosts

The following ports must be available. On some systems, these ports are open by default.

  • TCP port 2377 for cluster management communications
  • TCP and UDP port 7946 for communication among nodes
  • UDP port 4789 for overlay network traffic

e. init SWARM

$ docker swarm init — advertise-addr 67.205.189.189
Image1

2 Add nodes to the swarm

Once you’ve created a swarm with a manager node, you’re ready to add worker nodes.

  1. Install docker for centos 7
$ yum install -y yum-utils
$ yum-config-manager - add-repo https://download.docker.com/linux/centos/docker-ce.repo
$ yum install docker-ce docker-ce-cli containerd.io
  1. Start Docker
$ systemctl start docker
  1. Add a worker to the swarm

To add a worker to this swarm, run the following command:

docker swarm join-token worker

Example :

Machine Master

[root@masterswarm ~]# docker swarm join-token worker
docker swarm join - token SWMTKN-1–5lscx6vk8jobgiw4fvr14aw359i3ma3wzs279af4ch8u9cqOOy-41gx6iw1bgjnllz0v0cy3h2tc 67.205.189.189:2377

Machine Worker

[root@worker1 ~]# docker swarm join — token SWMTKN-1–5lscx6vk8jobgiw4fvr14aw359i3ma3wzs279af4ch8u9cqOOy-41gx6iw1bgjnllz0v0cy3h2tc 67.205.189.189:2377

This node joined a swarm as a worker.

3 Manager “node ls” command to see the worker nodes:

Manager “node ls” command to see the worker nodes:

[root@masterswarm ~]# docker node ls
pm8x8qoowdp0lzppmn3ujnbyy worker1 Ready Active 19.03.13
e6a7hj998sr8a9xqfso0r3i6a worker2 Ready Active 19.03.13

Now your swarm consists of a manager and two worker nodes.

Image4

Hope this will help!

if you like my article :

NHAILA Achraf

#devsecops #devops #dockerswarm #swarm #cluster