{"id":683,"date":"2017-09-10T06:32:04","date_gmt":"2017-09-10T06:32:04","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=683"},"modified":"2017-09-10T06:32:04","modified_gmt":"2017-09-10T06:32:04","slug":"how-to-setup-and-configure-docker-swarm-cluster","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=683","title":{"rendered":"How to Setup and Configure Docker Swarm Cluster"},"content":{"rendered":"<p>In this tutorial, you will learn how to set up a four node docker swarm cluster.<\/p>\n<h3 id=\"prerequisites\">Prerequisites<\/h3>\n<ul>\n<li>Minimum two nodes with Docker installed ( swarm manager and cluster nodes)<\/li>\n<li>All the nodes should be able to talk to each other using public or private IP addresses.<\/li>\n<\/ul>\n<p>In this setup, I have total 4 nodes. 1 Swarm manager node and three other nodes to join the cluster with the following private IP addresses<\/p>\n<pre><code>Manager - 10.140.0.2\nNode1   - 10.140.0.6\nNode2   - 10.140.0.4\nMode3   - 10.140.0.5<\/code><\/pre>\n<p>Follow the steps given below for a multi node swarm cluster.<\/p>\n<h3 id=\"on-manager-node\">On Manager Node<\/h3>\n<p>1. Execute the following command with the manager nodes IP for initializing the swarm cluster. <\/p>\n<pre><code>docker swarm init --advertise-addr &lt;MANAGER-IP&gt;<\/code><\/pre>\n<p>For example, <\/p>\n<pre><code>docker swarm init --advertise-addr 10.140.0.2\n<\/code><\/pre>\n<p>You will get the following output once swarm is initialized.<\/p>\n<pre><code>[devopscube@manager ~]$ docker swarm init --advertise-addr 10.140.0.2\nSwarm initialized: current node (0qjtv7kblhbrbub4yyk1tq1e7) is now a manager.\n\nTo add a worker to this swarm, run the following command:\n\n    docker swarm join \\\n    --token SWMTKN-1-3l50pb6ko5ci23134wzt17gqkb4nsbv4e52ciwdwq80hmmx1si-d3kv6s6qtgf0crqmz9dxix2oc \\\n    10.140.0.2:2377\n\nTo add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.\n\n[devopscube@manager ~]$<\/code><\/pre>\n<p>As you can see, the output has the steps to join other nodes to this swarm manager node.<\/p>\n<p><!--kg-card-begin: html--><\/p>\n<ol start=\"2\">\n<li>To know the swarm cluster info, execute the following command.<\/li>\n<\/ol>\n<p><!--kg-card-end: html--><\/p>\n<pre><code>docker info<\/code><\/pre>\n<p>In the output, you will see the following.<\/p>\n<pre><code>Swarm: active\n NodeID: 0qjtv7kblhbrbub4yyk1tq1e7\n Is Manager: true\n ClusterID: zj0ioxrvl0tsyxasbhwyu947l\n Managers: 1\n Nodes: 1<\/code><\/pre>\n<p><!--kg-card-begin: html--><\/p>\n<ol start=\"3\">\n<li>To know the information about all the nodes in the cluster, you can run the following command.<\/li>\n<\/ol>\n<p><!--kg-card-end: html--><\/p>\n<pre><code>docker node ls<\/code><\/pre>\n<h3 id=\"on-node-1-2-and-3\">On Node 1, 2 and 3<\/h3>\n<p>Now that we have the swarm manager ready, we can add our other nodes to the manager to form a multi node cluster.<\/p>\n<ol>\n<li>Execute the swarm join command from the manager output on all the extra nodes as shown below. The swarm token and IP will change based on your environment.<\/li>\n<\/ol>\n<blockquote><p><strong>Note:<\/strong> You can get the swarm token with the command by executing <code>docker swarm join-token worker<\/code> on the manager node.<\/p><\/blockquote>\n<pre><code>sudo docker swarm join \\    \n--token SWMTKN-1-3l50pb6ko5ci23134wzt17gqkb4nsbv4e52ciwdwq80hmmx1si-d3kv6s6qtgf0crqmz9dxix2oc  \\\n10.140.0.2:2377\n<\/code><\/pre>\n<h3 id=\"swarm-configuration-and-testing\">Swarm Configuration and Testing<\/h3>\n<p>1. Once you joined all the extra nodes, you can list the swarm node information by executing the following command on the manager node.<\/p>\n<pre><code>sudo docker node ls<\/code><\/pre>\n<p>You will get the output will the swarm cluster info as shown below.<\/p>\n<pre><code>[devopscube@manager ~]$ sudo docker node ls\nID                           HOSTNAME     STATUS  AVAILABILITY  MANAGER STATUS\n0qjtv7kblhbrbub4yyk1tq1e7 *  manager  Ready   Active        Leader\nadig05zbyuxt4x0oltrbrc523    node2        Ready   Active        \nbzupprwwasy6vvwh4hn0s4txz    node1        Ready   Active        \nug20slq1qyk6uzwgfv3a5zd86    node3        Ready   Active<\/code><\/pre>\n<p>Now our cluster is ready. You can start deploying applications to your swarm cluster.<\/p>\n<hr>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/logo-3.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"134\" height=\"111\"><\/figure>\n<p><!--kg-card-begin: html--><br \/>\n<span style=\"color: #333333;\"><strong>ONLINE COURSE:<\/strong> &nbsp;Docker Mastery: The Complete Toolset From a Docker Captain<\/span><br \/>\n<!--kg-card-end: html--><\/p>\n<p>Check out the docker course which thousands of students have already enrolled.<\/p>\n<p><a href=\"https:\/\/devopscube.com\/recommends\/docker-course\/\" rel=\"noopener\">Docker Mastery: The Complete Toolset From a Docker Captain<\/a><\/p>\n<ul>\n<li>Learn Docker and Compose<\/li>\n<li>Best practices for making Dockerfiles<\/li>\n<li>Learn to build multi node swarm cluster<\/li>\n<li>Rolling application deployments without downtime<\/li>\n<\/ul>\n<hr>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/how-to-setup-and-configure-docker-swarm-cluster\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to Setup and Configure Docker Swarm Cluster \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/how-to-setup-and-configure-docker-swarm-cluster\/<\/p>\n","protected":false},"author":1,"featured_media":684,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-683","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=683"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/683\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/684"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}