How To Setup a Docker Swarm Cluster on Ubuntu 16.04/18.04/20.04 LTS

Docker Swarm is a device that permits you to send a bunch of Docker Hosts. It’s a local bunching apparatus gave by Docker which gives high-accessibility and superior for your application by conveying it to all hubs inside the multitude group.

To begin, you will require:

1. Information on Docker and Ubuntu variant 16.04
2. An IP address that is designed on Worker Node and Manager Node.
3. 2 machines with Docker installed
Docker Clusters includes two significant parts:
Manager Nodes

They manage the board of bunches including keeping up the condition of groups, planning of administrations, and overhauling swarm mode endpoints (HTTP API). A vital element in the administrator majority that store basic information about the Swarm group.


Worker Nodes

These execute holders. They are not engaged with booking choices. A Worker hub must have no short of what one Manager Node. It’s conceivable to overhaul a laborer hub to a Manager hub when a last is under upkeep.

Step 1: Update the System

Before you start, You need to update the current ubuntu repository system is up-to-date. Use the command below to update it.

$ sudo apt-get update



Step 2: Add Docker Repository

Introduce Docker machine on every one of the hubs. Since Docker Swarm is doesn’t exist in the default method of Ubuntu variant 16.04 default, you have to run it first. 

$ sudo apt install software-properties-common apt-transport-https ca-certificates -y


$ sudo curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -


$ sudo echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" > /etc/apt/sources.list.d/docker-ce.list



Step 3: Install Docker-CE

To install the docker packer you need to use the following command.

$ sudo apt update


$ sudo apt install docker-ce



Step 4: Controlling Docker Service

After installation of docker on your machine, You can check the docker’s service status by using the following command.

$ sudo systemctl status docker.service

  # To get docker status 

$ sudo systemctl start docker.service

   # To start the docker service 

$ sudo systemctl stop docker.service

    # To stop the docker service

$ sudo systemctl enable docker.service

  # On boot auto start the docker service 

$ sudo systemctl disable docker.service

# To stop on boot docker service.

Step 5: Enable Docker Swan clustering tool

Docker Swarm is a clustering and scheduling tool for Docker containers.

# Configure the Manager Node for Swarm Cluster Initialization

$ sudo docker swarm init --advertise-addr 192.168.1.103



# Configure Worker Nodes to join the Swarm Cluster

$ sudo docker swarm join --token SWMTKN-1-4htf3vnzmbhc88vxjyguipo91ihmutrxi2p1si2de4whaqylr6-3oed1hnttwkalur1ey7zkdp9l 192.168.1.103:2377



Step 6: Docker Swarm Basic Commands


Here some useful command to create your first docker swarn cluster, You can create your own service with number of replica, here we are going to create nginx docker swarn replication service.

To create service with nginx images.


$ sudo docker service create --name swarn-aftab --publish 9696:80 --replicas 4 nginx

  


To get cluster nodes.


 

$ sudo docker node ls

 


To get service listing


$ sudo docker service ls

 


To scale up or scale down the replica’s number


$ sudo docker service scale swarn-aftab=3

  


To get process details.


$ sudo docker service ps swarn-aftab

To remove the service from the cluster.


$ sudo docker service rm swarn-aftab

 


Conclusion


Congrats! It’s as basic as that. Presently you have a total set up of Docker Swarm on Ubuntu adaptation 16.04. Likewise, you presently realize how to do a few administration undertakings on Swarm Cluster. With this essential arrangement, you actually need to design your Docker group with a few Manager Node relying upon your organization’s prerequisites.

How To Setup a Docker Swarm Cluster on Ubuntu 16.04/18.04/20.04 LTS

Leave a Reply

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

Scroll to top