Install Docker Swarm cluster

#Introduction

In this tutorial, How to Install Docker Swarm cluster. Docker Swarm is a way to create a cluster for container deployment.

With a minute you can deploy the cluster up and running for high availability, failover, and scalability.

To install a Docker Swarm cluster, you will need multiple nodes or machines that will act as Swarm managers and workers

Here’s a step-by-step guide on how to install Docker Swarm

Prerequisites

  • Host OS: Ubuntu 21.04
  • 1 Controller.
  • 2 nodes.
  • Installed Docker on your controller and node.

How to install Docker Swarm cluster

1. Log into the Docker Swarm controller

We run the command line as below:

sudo apt-get update -y
sudo apt-get install ca-certificates curl gnupg lsb-release -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y 
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
newgrp docker

2. Log into Docker Swarm Node1

We run the command line as below:

sudo apt-get update -y
sudo apt-get install ca-certificates curl gnupg lsb-release -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y 
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
newgrp docker

3. Log into Docker Swarm Node2

We run the command line as below:

sudo apt-get update -y
sudo apt-get install ca-certificates curl gnupg lsb-release -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y 
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
newgrp docker

For example, as the picture below:

Install Docker Swarm cluster

Back at the Server Docker Controller, initialize the swarm with as command below:

docker swarm init --advertise-addr 192.168.56.11
Install Docker Swarm cluster 1

You can see with the join command that will look something as below

docker swarm join --token SWMTKN-1-1godvlo74ufchdrmck9earbshkxa2u91w7ss742bryl40f7c8i-aq684grkb94d7vaguh4aep7rt 192.168.56.11:2377

Log into Node1 run the command docker swarm join

Install Docker Swarm cluster 2

Log into Node2 run the command docker swarm join

Install Docker Swarm cluster 3

We will verify the result on the Server controller:

docker info
Install Docker Swarm cluster 4

Conclusion

You have successfully installed a Docker Swarm cluster and deployed services to it. You can continue exploring Docker Swarm features to manage and scale your applications effectively. I hope will this your helpful. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

2 thoughts on “Install Docker Swarm cluster

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.