This article is for those looking for a detailed and clear guide on how to install Docker Swarm on Ubuntu Server.

Docker Swarm is a clustering tool for Docker that transforms a collection of Docker servers into a single cluster. Docker Swarm ensures availability and high performance by distributing it across Docker servers within the cluster.

In this guide, we will consider the case when you already have a server with the Ubuntu Server 20.04 LTS operating system installed on it.

You can read more about how to install Ubuntu Server 20.04 LTS in my guide “Install Ubuntu Server 20.04 LTS”.

Also, the Docker Engine must be installed on the server.

You can learn how to install Docker Engine on Ubuntu Server by reading “Install Docker Engine on Ubuntu Server”.

In addition, OpenSSH must be installed on the server, and port 22 must be open in order to be able to connect to the server using the SSH protocol.

To install OpenSSH on a server, you can use the command:

sudo apt install openssh-server

If you plan to connect to the server using the Windows operating system, you can use PuTTY, a free client for various remote access protocols, including SSH, Telnet, rlogin.

This guide describes how to connect to a server using the iTerm2 terminal emulator installed on the macOS operating system.

Please note that you will need to open the following TCP and UDP ports to access your server:

  • TCP port 2377 - for cluster management and Raft synchronization.
  • TCP and UDP port 7946 - for communication between all Docker Swarm servers.
  • UDP port 4789 - for network traffic (inbound container network).
  • IP Protocol 50 (ESP) - if you plan to use an encrypted network.

We connect to the server on which you plan to install Docker Swarm.

Let’s see the IP address of the server using the command:

ip a

Install Docker Swarm on Ubuntu Server

We activate Docker Swarm using the command:

docker swarm init --advertise-addr 10.170.18.13

Install Docker Swarm on Ubuntu Server

Please note 10.170.18.13 is the IP address of my server. Accordingly, you need to specify the IP address of your server.

Docker Swarm is activated.

Using the command shown on the screen, you can join another server with the “Worker” role to the Docker Swarm cluster.

Please note that to prepare another server for the Docker Swarm cluster, you need to install only the Docker Engine on the new server and run the docker swarm join command with the appropriate token.

You can learn how to install Docker Engine on Ubuntu Server by reading “Install Docker Engine on Ubuntu Server”.

Now we will get the token for joining the new server with the “Manager” role to the Docker Swarm cluster using the command:

docker swarm join-token manager

Install Docker Swarm on Ubuntu Server

Using the command shown on the screen, you can join another server with the “Manager” role to the Docker Swarm cluster.

Please note that to prepare another server for the Docker Swarm cluster, you need to install only the Docker Engine on the new server and run the docker swarm join command with the appropriate token.

Now you need to make sure that Docker Swarm is installed correctly. To do this, you need to run the command:

docker info

Judging by the message received, Docker Swarm is installed correctly.

Install Docker Swarm on Ubuntu Server

You can learn how to install Docker Compose on Ubuntu Server by reading “Install Docker Compose on Ubuntu Server”.

Vladimir Mikhalev
hey, I’m Vladimir Mikhalev, but my friends call me Valdemar. I have a lot of experience in the design and maintenance of various information systems.

Recent Posts