{"id":84874,"date":"2021-02-15T13:54:42","date_gmt":"2021-02-15T10:54:42","guid":{"rendered":"https:\/\/computingforgeeks.com\/?p=84874"},"modified":"2023-11-04T15:41:11","modified_gmt":"2023-11-04T12:41:11","slug":"install-docker-swarm-cluster-on-debian","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/install-docker-swarm-cluster-on-debian\/","title":{"rendered":"Install Docker Swarm Cluster on Debian 12\/11\/10"},"content":{"rendered":"\n<p>Welcome to today&#8217;s guide on how to install Docker Swarm Cluster on Debian 12\/11\/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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Worker nodes are instances of Docker engine which execute the containers.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"762\" height=\"365\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2021\/02\/setup-Docker-swarm-on-debian-10.png\" alt=\"\" class=\"wp-image-84877\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2021\/02\/setup-Docker-swarm-on-debian-10.png 762w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2021\/02\/setup-Docker-swarm-on-debian-10-300x144.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2021\/02\/setup-Docker-swarm-on-debian-10-696x333.png 696w\" sizes=\"auto, (max-width: 762px) 100vw, 762px\" \/><\/figure>\n\n\n\n<p>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&#8217;t auto-scale basing on monitoring and resource utilization. You have to scale the containers manually.<\/p>\n\n\n\n<p>This guide will discuss how to setup a Docker Swarm cluster on <meta charset=\"utf-8\">Debian 11 \/ Debian 10 hosts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1 &#8211; Node preparation<\/h2>\n\n\n\n<p>Configure the hostnames for each node in the <code>\/etc\/hosts<\/code> file for local resolution.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vim \/etc\/hosts<\/code><\/pre>\n\n\n\n<p>Add the details of the nodes on each server, both the manager and the worker nodes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10.31.45.182    manager\n10.31.45.226    worker-01\n10.31.45.219    worker-02<\/code><\/pre>\n\n\n\n<p>Ensure the hosts can reach each other via ping.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2 &#8211; Install Docker CE<\/h2>\n\n\n\n<p>We need to install Docker engine on all the hosts, manager and worker nodes.<\/p>\n\n\n\n<p>Install dependency packages on the hosts:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get update\nsudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common\n<\/code><\/pre>\n\n\n\n<p>Add Docker GPG key:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -fsSL https:\/\/download.docker.com\/linux\/debian\/gpg | sudo apt-key add -<\/code><\/pre>\n\n\n\n<p>Add Docker repository:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo add-apt-repository \"deb &#91;arch=amd64] https:\/\/download.docker.com\/linux\/debian $(lsb_release -cs) stable\"<\/code><\/pre>\n\n\n\n<p>Install Docker Engine<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install docker-ce docker-ce-cli<\/code><\/pre>\n\n\n\n<p>Start and enable Docker<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl start docker\nsudo systemctl enable docker<\/code><\/pre>\n\n\n\n<p>Add your user to docker group<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo usermod -aG docker ${USER}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3 &#8211; Initialize Docker Swarm Cluster<\/h2>\n\n\n\n<p>In this step, we need to initialize Docker swarm mode on the manager node then we can later add the worker nodes. <\/p>\n\n\n\n<p>The command below is used to initialize Docker Swarm Manager. You should replace the <em><strong>&lt;manager-IP&gt;<\/strong> <\/em>Address with the IP of your manager node.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>newgrp docker\nsudo docker swarm init --advertise-addr &lt;manager-IP&gt;<\/code><\/pre>\n\n\n\n<p>Sample output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">docker swarm init --advertise-addr <\/mark><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">10.31.45.182<\/mark>\n\nSwarm initialized: current node (xj5sqdpsbs5x2pgt670dft31m) is now a manager.\n\nTo add a worker to this swarm, run the following command:\n\n    docker swarm join --token SWMTKN-1-5yat7zlum78qmnlhv1vs0b0k4c42jafh5kt8xtb36eara4c5ip-490dr4yhpbe5qnic476wh90zg 10.31.45.182:2377\n\nTo add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.<\/code><\/pre>\n\n\n\n<p>With the manager node initialized,we can now add the worker nodes using the join-token that is given in the sample above.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">docker swarm join --token SWMTKN-1-5yat7zlum78qmnlhv1vs0b0k4c42jafh5kt8xtb36eara4c5ip-490dr4yhpbe5qnic476wh90zg 10.31.45.182:2377<\/mark>\n\nThis node joined a swarm as a worker.<\/code><\/pre>\n\n\n\n<p>We can check if the worker nodes have joined to cluster successfully using the command below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo docker node ls<\/code><\/pre>\n\n\n\n<p>Sample output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">docker node ls<\/mark>\nID                            HOSTNAME   STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION\nh673oapwzqcsoszm36dcsyx4u     worker-01     Ready     Active                          20.10.3\ntg30e58pf2ebktyu5geg5hjzd     worker-02     Ready     Active                          20.10.3\nvhqes84cz4ljrrj8ux9bx9jzv     worker-03     Ready     Active                          20.10.3\nxj5sqdpsbs5x2pgt670dft31m *   manager       Ready     Active         Leader           20.10.3<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4 &#8211; Deploy Applications on Docker Swarm<\/h2>\n\n\n\n<p>Here, we will deploy a web application on our cluster. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker service create --name webserver -p 8080:80 nginx<\/code><\/pre>\n\n\n\n<p>The above command deploys Nginx application on the cluster and is exposed on port 8080.<\/p>\n\n\n\n<p>To confirm if the service is running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">docker service ls<\/mark>\nID             NAME        MODE         REPLICAS   IMAGE          PORTS\nz383boupqk5p   webserver   replicated   1\/1        nginx:latest   *:80->80\/tcp<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Scale Applications on Docker Swarm<\/h3>\n\n\n\n<p>You can scale applications on your Docker Swarm Cluster for high availability and high performance.<\/p>\n\n\n\n<p>The command below is used:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker service scale webserver=4<\/code><\/pre>\n\n\n\n<p>Where <strong>webserver=4<\/strong> is the name of the application and the number of total containers to be up after the replication.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"145\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2021\/02\/install-docker-swarm-on-on-debian-10.png\" alt=\"\" class=\"wp-image-84883\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2021\/02\/install-docker-swarm-on-on-debian-10.png 624w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2021\/02\/install-docker-swarm-on-on-debian-10-300x70.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<p>You can verify the replicas with the command below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker service ls<\/code><\/pre>\n\n\n\n<p>Sample output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"742\" height=\"83\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2021\/02\/setup-docker-swarm-on-debian10.png\" alt=\"\" class=\"wp-image-84885\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2021\/02\/setup-docker-swarm-on-debian10.png 742w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2021\/02\/setup-docker-swarm-on-debian10-300x34.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2021\/02\/setup-docker-swarm-on-debian10-696x78.png 696w\" sizes=\"auto, (max-width: 742px) 100vw, 742px\" \/><\/figure>\n\n\n\n<p>We have successfully deployed our Docker Swarm cluster on <meta charset=\"utf-8\"><\/meta>Debian hosts.<\/p>\n\n\n\n<p>Check out these other articles from this website;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a aria-label=\"How To Install Docker Swarm On Ubuntu 20.04 (opens in a new tab)\" class=\"rank-math-link\" href=\"https:\/\/computingforgeeks.com\/how-to-install-docker-swarm-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">How To Install Docker Swarm On Ubuntu<\/a><\/li>\n\n\n\n<li><a class=\"rank-math-link\" href=\"https:\/\/computingforgeeks.com\/how-to-run-local-kubernetes-clusters-in-docker\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to run local Kubernetes Cluster in Docker Containers<\/a><\/li>\n\n\n\n<li><a class=\"rank-math-link\" href=\"https:\/\/computingforgeeks.com\/deploy-kubernetes-cluster-on-ubuntu-with-kubeadm\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to install Kubernetes Cluster on Ubuntu with kubeadm<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to today&#8217;s guide on how to install Docker Swarm Cluster on Debian 12\/11\/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 &#8230; <a title=\"Install Docker Swarm Cluster on Debian 12\/11\/10\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/install-docker-swarm-cluster-on-debian\/\" aria-label=\"Read more about Install Docker Swarm Cluster on Debian 12\/11\/10\">Read more<\/a><\/p>\n","protected":false},"author":17,"featured_media":84877,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[316,26,27,299,50],"tags":[217,35710],"class_list":["post-84874","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-containers","category-debian","category-docker","category-how-to","category-linux-tutorials","tag-docker","tag-docker-swarm"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/84874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=84874"}],"version-history":[{"count":0,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/84874\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/84877"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=84874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=84874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=84874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}