Install Docker Swarm Cluster on Debian 11 / Debian 10

Posted on 178 views

Welcome to today’s guide on how to install Docker Swarm Cluster on Debian 11 / Debian 10. Docker Swarm is a tool used to orchestrate docker hosts. We can create a high availability and a high performance Docker cluster with applications distributed among the hosts.

Docker swam uses a manager host and worker nodes architecture. You can have one or several manager nodes in your docker swarm cluster. The manager nodes uses the native Docker API and share the database of the Docker Swarm cluster with the worker nodes. The manager hosts maintain the cluster state, schedule tasks and handle the HTTP API endpoints.

Worker nodes are instances of Docker engine which execute the containers.


Unlike Kubernetes, which comes with a complete set of features like monitoring, ingress and volumes, Docker swarm comes with a much simpler state. Docker Swarm also lacks the auto-scaling feature whereby the containers can’t auto-scale basing on monitoring and resource utilization. You have to scale the containers manually.

This guide will discuss how to setup a Docker Swarm cluster onDebian 11 / Debian 10 hosts.

Step 1 – Node preparation

Configure the hostnames for each node in the /etc/hosts file for local resolution.

sudo vim /etc/hosts

Add the details of the nodes on each server, both the manager and the worker nodes.	manager    worker-01    worker-02

Ensure the hosts can reach each other via ping.

Step 2 – Install Docker CE onDebian 11 / Debian 10

We need to install Docker engine on all the hosts, manager and worker nodes.

Install dependency packages on the hosts:

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Add Docker GPG key:

curl -fsSL | sudo apt-key add -

Add Docker repository:

sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"

Install Docker Engine

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli

Start and enable Docker

sudo systemctl start docker
sudo systemctl enable docker

Add your user to docker group

sudo usermod -aG docker $USER

Step 3 – Initialize Docker Swarm Cluster

In this step, we need to initialize Docker swarm mode on the manager node then we can later add the worker nodes.

The command below is used to initialize Docker Swarm Manager. You should replace the  Address with the IP of your manager node.

newgrp docker
sudo docker swarm init --advertise-addr 

Sample output:

$ docker swarm init --advertise-addr

Swarm initialized: current node (xj5sqdpsbs5x2pgt670dft31m) is now a manager.

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

    docker swarm join --token SWMTKN-1-5yat7zlum78qmnlhv1vs0b0k4c42jafh5kt8xtb36eara4c5ip-490dr4yhpbe5qnic476wh90zg

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

With the manager node initialized,we can now add the worker nodes using the join-token that is given in the sample above.

$ docker swarm join --token SWMTKN-1-5yat7zlum78qmnlhv1vs0b0k4c42jafh5kt8xtb36eara4c5ip-490dr4yhpbe5qnic476wh90zg

This node joined a swarm as a worker.

We can check if the worker nodes have joined to cluster successfully using the command below:

sudo docker node ls

Sample output:

$ docker node ls
h673oapwzqcsoszm36dcsyx4u     worker-01     Ready     Active                          20.10.3
tg30e58pf2ebktyu5geg5hjzd     worker-02     Ready     Active                          20.10.3
vhqes84cz4ljrrj8ux9bx9jzv     worker-03     Ready     Active                          20.10.3
xj5sqdpsbs5x2pgt670dft31m *   manager       Ready     Active         Leader           20.10.3

Deploy Applications on Docker Swarm

Here, we will deploy a web application on our cluster.

$ docker service create --name webserver -p 8080:80 nginx

The above command deploys Nginx application on the cluster and is exposed on port 8080.

To confirm if the service is running:

$ docker service ls

ID             NAME        MODE         REPLICAS   IMAGE          PORTS
z383boupqk5p   webserver   replicated   1/1        nginx:latest   *:80->80/tcp

Scale Applications on Docker Swarm

You can scale applications on your Docker Swarm Cluster for high availability and high performance.

The command below is used:

$ docker service scale webserver=4

Where webserver=4 is the name of the application and the number of total containers to be up after the replication.


You can verify the replicas with the command below:

$ docker service ls

Sample output:


We have successfully deployed our Docker Swarm cluster onDebian 11 / Debian 10 hosts.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.