{"id":43349,"date":"2017-01-30T11:00:19","date_gmt":"2017-01-30T09:00:19","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=43349"},"modified":"2022-07-08T16:12:07","modified_gmt":"2022-07-08T13:12:07","slug":"docker-swarm-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/","title":{"rendered":"Docker Swarm Tutorial"},"content":{"rendered":"<h2 class=\"wp-block-heading\" id=\"h-1-introduction\"><a name=\"introduction\"><\/a>1. Introduction<\/h2>\n<p>This post introduces Docker Swarm &#8211; the Docker Engine&#8217;s Swarm mode. The Swarm mode enables multiple machines running Docker Engines to collaborate in a cluster. Let us explore the basics of this.<br \/>&nbsp;<br \/>&nbsp;<br \/>&nbsp;<br \/>&nbsp;<br \/>&nbsp;<br \/>&nbsp;<br \/>&nbsp;<\/p>\n<p>&nbsp;<br \/>To follow the examples provided here you will need Docker Engine 1.12 or above to be installed in your machine. You will also need to install VirualBox, and two virtual machines running Ubuntu 16.04 LTS server edition.&nbsp; Let us get started.<\/p>\n<p>You can also check this tutorial in the following video:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/youtu.be\/1wnQTuc4H98\"><img decoding=\"async\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Docker-Swarm-Tutorial-1024x576.jpg\" alt=\"\" class=\"wp-image-113895\" width=\"512\" height=\"288\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Docker-Swarm-Tutorial-1024x576.jpg 1024w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Docker-Swarm-Tutorial-300x169.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Docker-Swarm-Tutorial-768x432.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Docker-Swarm-Tutorial.jpg 1280w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/a><figcaption>Docker Swarm Tutorial &#8211; Video<\/figcaption><\/figure>\n<\/div>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#whatisdockerswarm\">2. What is Docker Swarm?<\/a><\/dt>\n<dt><a href=\"#swarmsetup\">3. Setup the tools required to setup a multi-node swarm<\/a><\/dt>\n<dt><a href=\"#startswarmmachine\">4. Start the swarm-manager machine<\/a><\/dt>\n<dt><a href=\"#startswarmworkers\">5. Start the worker-node machines<\/a><\/dt>\n<dt><a href=\"#swarmstatus\">6. Verify the status of the swarm in the swarm manager<\/a><\/dt>\n<dt><a href=\"#deployservice\">7. Deploy a service<\/a><\/dt>\n<dt><a href=\"#scaleservice\">8. Scale the service<\/a><\/dt>\n<dt><a href=\"#removeservice\">9. Remove the service<\/a><\/dt>\n<dt><a href=\"#summary\">10. Summary<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-2-what-is-docker-swarm\"><a name=\"whatisdockerswarm\"><\/a>2. What is Docker Swarm?<\/h2>\n<p><a href=\"https:\/\/www.docker.com\/products\/docker-swarm\">Docker Swarm<\/a> is Docker&#8217;s native feature to support clustering of Docker machines. This enables multiple machines running Docker Engine to participate in a cluster, called <em>Swarm<\/em>. The Docker engines contributing to a Swarm are said to be running in <em>Swarm mode<\/em>. Machines enter into the Swarm mode by either initializing a new swarm or by joining an existing swarm. To the end user the swarm would seem like a single machine. A Docker engine participating in a swarm is called a <em>node<\/em>. A node can either be a <em>manager node<\/em> or a <em>worker node<\/em>. The manager node performs cluster management and orchestration while the worker nodes perform tasks allocated by the manager.<\/p>\n<p>A manager node itself, unless configured otherwise, is also be a worker node. The central entity in the Docker Swarm infrastructure is called a <em>service<\/em>. A Docker swarm executes services. The user submits a <em>service<\/em> to the manager node to deploy and execute. A service is made up of many <em>tasks<\/em>. A <em>task<\/em> is the most basic work unit in a Swarm. A task is allocated to each worker node b the manager node.<\/p>\n<p>Services can be scaled at runtime to handle extra load. The swarm manager natively supports internal load balancing to distribute tasks across the participating worker nodes. Also, the manager also supports ingress load balancing to control exposure of Docker services to the external world. The manager node also supports service discovery by automatically assigning a DNS entry to every service.<\/p>\n<p>More details about these concepts can be found from the <a href=\"https:\/\/docs.docker.com\/engine\/swarm\/key-concepts\/\">official Docker documentation<\/a>. We will now proceed to setup a basic multi-node Docker Swarm setup to understand it further.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-3-setup-the-tools-required-to-setup-a-multi-node-swarm\"><a name=\"swarmsetup\"><\/a>3. Setup the tools required to setup a multi-node swarm<\/h2>\n<p>Here is what you will need to setup the infrastructure for the rest of this post. Basically, I setup a Docker machine and two different virtual machines on my laptop. The host operating system was Ubuntu 16.04 Server and the guest OS for the virtual machines were also Ubuntu 16.04 server.<br \/>1. Install Oracle VirtualBox 5.1 <a href=\"https:\/\/www.virtualbox.org\/wiki\/Downloads\">from here<\/a>.<br \/>2. Download Ubuntu Server 16.04 LTS ISO image, for installing into the VMs, <a href=\"https:\/\/www.ubuntu.com\/download\/server\">from here<\/a>.<br \/>3. Create 2 VMs in VirtualBox using the ISO image downloaded above.<\/p>\n<p>Instructions to create a Ubuntu Server VM in VirtualBox can be <a href=\"http:\/\/askubuntu.com\/a\/153098\">found here<\/a> or from <a href=\"https:\/\/www.youtube.com\/watch?v=PVhyOgy709U\">this video guide here<\/a>. I created 2 VMs called <em>hariharan-docker-swarm-worker-node-1<\/em> and <em>hariharan-docker-swarm-worker-node-2<\/em>.<br \/>4. Boot the 2 VMs and install the latest Docker Engine in both. Installation instructions for Ubuntu can be found <a href=\"https:\/\/docs.docker.com\/engine\/installation\/linux\/ubuntu\/\">from here<\/a>.<br \/>5. Create a docker machine called &#8220;docker-swarm-manager&#8221; with virtualbox as the driver.<\/p>\n<pre class=\"wp-block-preformatted\">$ docker-machine create --driver virtualbox docker-swarm-manager\n<\/pre>\n<p>The above command essentially creates a virtual machine in VirtualBox using the <a href=\"http:\/\/boot2docker.io\/\">Boot2Docker<\/a> image. Let us next start this machine and initialize a Docker Swarm in this.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-4-start-the-swarm-manager-machine\"><a name=\"startswarmmachine\"><\/a>4. Start the swarm-manager machine<\/h2>\n<pre class=\"wp-block-preformatted\">$ docker-machine start docker-swarm-manager\nStarting \"docker-swarm-manager\"...\n(docker-swarm-manager) Check network to re-create if needed...\n(docker-swarm-manager) Waiting for an IP...\nMachine \"docker-swarm-manager\" was started.\nWaiting for SSH to be available...\nDetecting the provisioner...\nStarted machines may have new IP addresses. You may need to re-run the `docker-machine env` command.\n$\n<\/pre>\n<p>Noe the Docker machine is started. We will use this as the Swarm manager node. So let us SSH into this machine and create a Swarm.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"wp-block-preformatted\">$ docker-machine ssh docker-swarm-manager\n$\n$ docker swarm init --advertise-addr 192.168.99.100\nSwarm initialized: current node (oex7thwlqimoy6wxddliyew9q) is now a manager.\n\nTo add a worker to this swarm, run the following command:\n\ndocker swarm join \\\n--token SWMTKN-1-1k0yuvvfpsid27slhn5of2ue0xjq91kqcb2qp81idyvt7amj5j-7t5fada5fqxw3wv3fk0cihoji \\\n192.168.99.100:2377\n\nTo add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.\n<\/pre>\n<p>The above command initialized a Swarm and made the above machine a manager node. It also provided instructions on how other nodes can join into the Swarm. Let us next join the other 2 VMs we created above into this Swarm.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-5-start-the-worker-node-machines\"><a name=\"startswarmworkers\"><\/a>5. Start the worker-node machines<\/h2>\n<p>Open VirtualBox and Start the VMs <em>hariharan-docker-swarm-worker-node-1<\/em>. Login into the terminal and give the following command:<\/p>\n<pre class=\"wp-block-preformatted\">$ docker swarm join --token SWMTKN-1-1k0yuvvfpsid27slhn5of2ue0xjq91kqcb2qp81idyvt7amj5j-7t5fada5fqxw3wv3fk0cihoji 192.168.99.100:2377\nThis node joined a swarm as a worker.\n<\/pre>\n<p>Repeat the same steps as above with the VM <em>hariharan-docker-swarm-worker-node-2<\/em> so that it also joins the swarm as a worker. So now, we should have a swarm of 3 nodes with one among them being a master node.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-6-verify-the-status-of-the-swarm-in-the-swarm-manager\"><a name=\"swarmstatus\"><\/a>6. Verify the status of the swarm in the swarm manager<\/h2>\n<p>Go into the terminal running the swarm-manager and type the command <code>docker info<\/code> in the manager node. It should show, among a lot of information, the information about swarms.<\/p>\n<pre class=\"wp-block-preformatted\">$ docker info\n...\n...\nSwarm: active\nNodeID: oex7thwlqimoy6wxddliyew9q\nIs Manager: true\nClusterID: tq0gkoqfujux2a20oidx8idjd\nManagers: 1\nNodes: 4\nOrchestration:\nTask History Retention Limit: 5\nRaft:\nSnapshot Interval: 10000\nNumber of Old Snapshots to Retain: 0\nHeartbeat Tick: 1\nElection Tick: 3\nDispatcher:\nHeartbeat Period: 5 seconds\nCA Configuration:\nExpiry Duration: 3 months\nNode Address: 192.168.99.100\nManager Addresses:\n192.168.99.100:2377\n...\n...\n<\/pre>\n<p>Another more specific way to to verify the same is through the command <code>docker node ls<\/code>, like below:<\/p>\n<pre class=\"wp-block-preformatted\">$ docker node ls\nID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HOSTNAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STATUS&nbsp; AVAILABILITY&nbsp; MANAGER STATUS\noex7thwlqimoy6wxddliyew9q *&nbsp; docker-swarm-manager&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ready&nbsp;&nbsp; Active&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Leader\nrcm93fzmoeb4gfxgzsavvmhfg&nbsp;&nbsp;&nbsp; hariharan-docker-swarm-worker-node-2&nbsp; Ready&nbsp;&nbsp; Active\nv673asfigzknhwmu5gk7gb3ng&nbsp;&nbsp;&nbsp; hariharan-docker-swarm-worker-node-1&nbsp; Ready&nbsp;&nbsp; Active\n<\/pre>\n<p>From the above output, it is seen that the host <em>docker-swarm-manager<\/em> is marked with a <strong>*<\/strong> indicating that is the manager node. The other 2 hosts above are the worker nodes. You can see the status of a specific node by using the command &#8211; <code>docker node inspect<\/code>. Let us inspect the node <em>hariharan-docker-swarm-worker-node-2<\/em> more, like so<\/p>\n<pre class=\"wp-block-preformatted\">$ docker node inspect --pretty hariharan-docker-swarm-worker-node-2\nID:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;        rcm93fzmoeb4gfxgzsavvmhfg\nHostname:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;      hariharan-docker-swarm-worker-node-2\nJoined at:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;       2017-01-28 13:20:10.217592895 +0000 utc\nStatus:\n  State:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;      Ready\n  Availability:&nbsp;&nbsp;      Active\n  Address:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;       192.168.99.1\nPlatform:\n  Operating System:&nbsp;&nbsp; &nbsp;linux\n  Architecture:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;x86_64\nResources:\n  CPUs:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;1\n  Memory:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;      992.3 MiB\nPlugins:\n  Network:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;     bridge, host, macvlan, null, overlay\n  Volume:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;      local\nEngine Version:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;1.13.0\n<\/pre>\n<p>Now that we have verified the setup, let us next deploy a simple service in the swarm.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-7-deploy-a-service\"><a name=\"deployservice\"><\/a>7. Deploy a service<\/h2>\n<p>In the manager node, give the below command to create a service. This service is based on the <a href=\"https:\/\/hub.docker.com\/r\/enhariharan\/infinite-loop\/\">very simple Docker image<\/a> that simply creates an infinite loop.[ulp id=&#8217;6PVIvOz3kDbYmNRn&#8217;]<\/p>\n<pre class=\"wp-block-preformatted\">$ docker service create --replicas 1 --name infinite-loop enhariharan\/infinite-loop\n4ybguvnthyiclecftvbtg0m3x\n<\/pre>\n<p>Above, we named the service as <em>infinite-loop<\/em> by the <code>--name<\/code> option. The option <code>--replicas<\/code> specifies the number of tasks present in this servicer.<br \/>Verify that the service is running by the following command<\/p>\n<pre class=\"wp-block-preformatted\">$ docker service ls\nID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; REPLICAS&nbsp; IMAGE\n4ybguvnthyic&nbsp; infinite-loop&nbsp; replicated&nbsp; 1\/1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enhariharan\/infinite-loop:latest\n<\/pre>\n<p>Now let us inspect the details of the service in the manager node.<\/p>\n<pre class=\"wp-block-preformatted\">$ docker service inspect --pretty infinite-loop\n\nID:                  4ybguvnthyiclecftvbtg0m3x\nName:                infinite-loop\nService Mode:        Replicated\n  Replicas:          1\nPlacement:\nUpdateConfig:\n  Parallelism:       1\nOn failure:          pause\n  Max failure ratio: 0\nContainerSpec:\n  Image:             enhariharan\/infinite-loop:latest@sha256:b746e8ac5a4027616e1c4e682030e9f1749d5297275f108d5215ec8cb00d65cb\nResources:\nEndpoint Mode:       vip\n<\/pre>\n<p>Let us also find out which node is running the service<\/p>\n<pre class=\"wp-block-preformatted\">$ docker service ps infinite-loop\nID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IMAGE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DESIRED STATE&nbsp; CURRENT STATE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ERROR&nbsp; PORTS\nujntt8yxy3yx&nbsp; infinite-loop.1&nbsp; enhariharan\/infinite-loop:latest&nbsp; docker-swarm-manager&nbsp; Running&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Running 3 minutes ago\n<\/pre>\n<p>Till now, we looked at the basics of creating a swarm, adding nodes to it, deploying a service and inspecting it&#8217;s details. Let us next look at the basics of scaling the service we deployed.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-8-scale-the-service\"><a name=\"scaleservice\"><\/a>8. Scale the service<\/h2>\n<p>Until now there was only one instance of the service running, that too in the manager node itself. Let us load up this swarm a bot more to understand it&#8217;s behavior. In the manager node, use the command <code>docker service scale<\/code> to scale the service.<\/p>\n<pre class=\"wp-block-preformatted\">$ docker service scale infinite-loop=10\ninfinite-loop scaled to 10\n<\/pre>\n<p>That&#8217;s that. Now let see the result of this scaling by using the command <code>docker service ps<\/code>.<\/p>\n<pre class=\"wp-block-preformatted\">$ docker service ps infinite-loop\nID            NAME              IMAGE                             NODE                                  DESIRED STATE  CURRENT STATE           ERROR  PORTS\nujntt8yxy3yx  infinite-loop.1   enhariharan\/infinite-loop:latest  docker-swarm-manager                  Running        Running 10 minutes ago\n78nbb9guclfz  infinite-loop.2   enhariharan\/infinite-loop:latest  docker-swarm-manager                  Running        Running 23 seconds ago\nzi285gwiuyjp  infinite-loop.3   enhariharan\/infinite-loop:latest  docker-swarm-manager                  Running        Running 23 seconds ago\nd942isrqxhwr  infinite-loop.4   enhariharan\/infinite-loop:latest  hariharan-ThinkPad-W510               Running        Running 4 seconds ago\n4gsyyuc4lo2c  infinite-loop.5   enhariharan\/infinite-loop:latest  hariharan-docker-swarm-worker-node-2  Running        Running 9 seconds ago\nirtte6ktum6y  infinite-loop.6   enhariharan\/infinite-loop:latest  hariharan-ThinkPad-W510               Running        Running 4 seconds ago\n70nawd6pjyiz  infinite-loop.7   enhariharan\/infinite-loop:latest  hariharan-docker-swarm-worker-node-1  Running        Running 9 seconds ago\nir6eqxnr30vc  infinite-loop.8   enhariharan\/infinite-loop:latest  hariharan-docker-swarm-worker-node-2  Running        Running 9 seconds ago\nq85imuo1hwai  infinite-loop.9   enhariharan\/infinite-loop:latest  hariharan-docker-swarm-worker-node-1  Running        Running 8 seconds ago\nnpr1mejjg76d  infinite-loop.10  enhariharan\/infinite-loop:latest  hariharan-docker-swarm-worker-node-1  Running        Running 8 seconds ago\n<\/pre>\n<p>We can see that the service has tasks distributed across all the nodes in the swarm now. The worker node <em>hariharan-docker-swarm-worker-node-1<\/em> spawned 3 tasks, <em>hariharan-docker-swarm-worker-node-2<\/em> spawned 2, the manager node <em>docker-swarm-manager<\/em> spawned 3, and the remaining 2 was taken up by another node that I spawned later in the host OS.<\/p>\n<p>To see the containers running on the manager node, the good old command <code>docker ps<\/code> will do the job. To see the container running on the worker node, SSH into the worker node and try the same <code>docker ps<\/code> command there.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-9-remove-the-service\"><a name=\"removeservice\"><\/a>9. Remove the service<\/h2>\n<p>Finally, let us remove the service. Use the command <code>docker service rm<\/code> to accomplish this, like below:<\/p>\n<pre class=\"wp-block-preformatted\">$ docker service rm infinite-loop\ninfinite-loop\n<\/pre>\n<p>and verify that the service was removed.<\/p>\n<pre class=\"wp-block-preformatted\">$ docker service ls\nID&nbsp; NAME&nbsp; MODE&nbsp; REPLICAS&nbsp; IMAGE\n<\/pre>\n<p>Verify that the containers pertaining to the service are also removed using <code>docker ps<\/code>:<\/p>\n<pre class=\"wp-block-preformatted\">$ docker ps\nCONTAINER ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IMAGE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMAND&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CREATED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STATUS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PORTS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NAMES\n<\/pre>\n<h2 class=\"wp-block-heading\" id=\"h-10-summary\"><a name=\"summary\"><\/a>10. Summary<\/h2>\n<p>In this post, we discussed the basic concepts of Docker Swarm mode. Docker engines provide support for container clustering and orchestration while it runs in the Swarm mode. A Docker engine, also called a node, enters the Swarm mode by wither initializing a new Swarm or by joining an existing one.<br \/>&nbsp;<br \/>We looked at how a swarm can be setup and started by using the various <code>docker swarm<\/code> CLI commands. We looked at some basic commands to manage and manipulate the service life cycle in a cluster using <code>docker service<\/code> commands. Finally, we looked at how to scale a service using the <code>docker service scale<\/code> command.<\/p>\n<p><strong>Last updated on Feb. 27th, 2022<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction This post introduces Docker Swarm &#8211; the Docker Engine&#8217;s Swarm mode. The Swarm mode enables multiple machines running Docker Engines to collaborate in a cluster. Let us explore the basics of this.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;To follow the examples provided here you will need Docker Engine 1.12 or above to be installed in your machine. You &hellip;<\/p>\n","protected":false},"author":103,"featured_media":31013,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1354],"tags":[],"class_list":["post-43349","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Docker Swarm Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"This post explains the basics of Docker Swarm mode and introduces the basic commands to setup and work with Swamr.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Docker Swarm Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"This post explains the basics of Docker Swarm mode and introduces the basic commands to setup and work with Swamr.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-30T09:00:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-08T13:12:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Hariharan Narayanan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hariharan Narayanan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/\"},\"author\":{\"name\":\"Hariharan Narayanan\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/780d96edfe3bce18c5440613fa88bce3\"},\"headline\":\"Docker Swarm Tutorial\",\"datePublished\":\"2017-01-30T09:00:19+00:00\",\"dateModified\":\"2022-07-08T13:12:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/\"},\"wordCount\":1257,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg\",\"articleSection\":[\"Docker\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/\",\"name\":\"Docker Swarm Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg\",\"datePublished\":\"2017-01-30T09:00:19+00:00\",\"dateModified\":\"2022-07-08T13:12:07+00:00\",\"description\":\"This post explains the basics of Docker Swarm mode and introduces the basic commands to setup and work with Swamr.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DevOps\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/devops\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Docker\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/devops\/docker\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Docker Swarm Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/780d96edfe3bce18c5440613fa88bce3\",\"name\":\"Hariharan Narayanan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/10\/Hariharan-Narayanan-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/10\/Hariharan-Narayanan-96x96.jpg\",\"caption\":\"Hariharan Narayanan\"},\"description\":\"Hari graduated from the School of Computer and Information Sciences in the University of Hyderabad. Over his career he has been involved in many complex projects in mobile applications, enterprise applications, distributed applications, micro-services, and other platforms and frameworks. He works as a consultant and is mainly involved with projects based on Java, C++ and Big Data technologies.\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/hariharan-narayanan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Docker Swarm Tutorial - Java Code Geeks","description":"This post explains the basics of Docker Swarm mode and introduces the basic commands to setup and work with Swamr.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Docker Swarm Tutorial - Java Code Geeks","og_description":"This post explains the basics of Docker Swarm mode and introduces the basic commands to setup and work with Swamr.","og_url":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-01-30T09:00:19+00:00","article_modified_time":"2022-07-08T13:12:07+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg","type":"image\/jpeg"}],"author":"Hariharan Narayanan","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Hariharan Narayanan","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/"},"author":{"name":"Hariharan Narayanan","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/780d96edfe3bce18c5440613fa88bce3"},"headline":"Docker Swarm Tutorial","datePublished":"2017-01-30T09:00:19+00:00","dateModified":"2022-07-08T13:12:07+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/"},"wordCount":1257,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg","articleSection":["Docker"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/","name":"Docker Swarm Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg","datePublished":"2017-01-30T09:00:19+00:00","dateModified":"2022-07-08T13:12:07+00:00","description":"This post explains the basics of Docker Swarm mode and introduces the basic commands to setup and work with Swamr.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/docker-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/docker-swarm-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"DevOps","item":"https:\/\/examples.javacodegeeks.com\/category\/devops\/"},{"@type":"ListItem","position":3,"name":"Docker","item":"https:\/\/examples.javacodegeeks.com\/category\/devops\/docker\/"},{"@type":"ListItem","position":4,"name":"Docker Swarm Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/780d96edfe3bce18c5440613fa88bce3","name":"Hariharan Narayanan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/10\/Hariharan-Narayanan-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/10\/Hariharan-Narayanan-96x96.jpg","caption":"Hariharan Narayanan"},"description":"Hari graduated from the School of Computer and Information Sciences in the University of Hyderabad. Over his career he has been involved in many complex projects in mobile applications, enterprise applications, distributed applications, micro-services, and other platforms and frameworks. He works as a consultant and is mainly involved with projects based on Java, C++ and Big Data technologies.","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/hariharan-narayanan\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/43349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/103"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=43349"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/43349\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/31013"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=43349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=43349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=43349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}