

{"id":37873,"date":"2018-12-02T10:56:28","date_gmt":"2018-12-02T05:26:28","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=37873"},"modified":"2018-12-02T10:56:28","modified_gmt":"2018-12-02T05:26:28","slug":"docker-swarm","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/docker-swarm\/","title":{"rendered":"Docker Swarm Mode &#8211; Features, Nodes and Filters"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Today, we will cover up the <strong>complete concept of Docker<\/strong> Swarm Mode. Though, to understand Swarm mode well, it is important to know about Swarm also. So, we will discuss the meaning of Swarm. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, we will look at features and nodes in Docker Swarm. Moreover, we will discuss Docker Swarm filters and load balancing. At last, we will see the task and services in Docker Swarm.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The cluster management and orchestration features which are embedded in Docker Engine is what we call Swarm mode. Basically, the Docker Engine runs in swarm mode when we initialize a new swarm (cluster) or join nodes to a swarm.\u00a0<\/span><\/p>\n<p>So, let&#8217;s begin Docker Swarm tutorial.<\/p>\n<h2><span style=\"font-weight: 400\">What is Swarm in Docker?<\/span><\/h2>\n<p><span style=\"font-weight: 400\">As we have mentioned above that by using swarm kit only the cluster management and orchestration features embedded in the Docker Engine are built. Well, a separate project which implements Docker\u2019s orchestration layer and which is directly used within Docker is what we call Swarmkit.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Basically, it consists of multiple Docker hosts that run in swarm mode and act as managers and workers. Here, managers manage the membership and delegation and workers run swarm services. However, a given Docker host can perform the role of a manager, a worker, or both. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Though, while we create a service, we define its optimal states such as network and storage resources available to it, number of replicas, ports the service exposes to the outside world, and many more. And, Docker actually works to maintain that desired state.<\/span><\/p>\n<p><span style=\"font-weight: 400\"> For example, if any worker node becomes unavailable then Docker schedules that node\u2019s tasks on other nodes. Moreover, a task is a running container that is part of a swarm service and managed by a swarm manager, as opposed to a standalone container.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Features of Docker Swarm<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Cluster management integrated with Docker Engine: <\/span><\/p>\n<p><span style=\"font-weight: 400\">In order to create a swarm of Docker Engines where we can deploy application services, we use the Docker Engine CLI. That says we don\u2019t need additional orchestration software to create or manage a swarm.<\/span><\/p>\n<h4><span style=\"font-weight: 400\">i. Scaling<\/span><\/h4>\n<p><span style=\"font-weight: 400\">We can declare the number of tasks we want to run, for each service. The swarm manager automatically adapts by adding or removing tasks to maintain the desired state, whenever we scale up or down.<\/span><\/p>\n<h4><span style=\"font-weight: 400\">ii. Multi-host networking<\/span><\/h4>\n<p><span style=\"font-weight: 400\">Also, we can specify an overlay network for our services. When swarm manager initializes or updates the application, it automatically assigns addresses to the containers on the overlay network.<\/span><\/p>\n<h4><span style=\"font-weight: 400\">iii. Service discovery<\/span><\/h4>\n<p><span style=\"font-weight: 400\">Nodes of Swarm manager assign each service in the swarm a unique DNS name as well as load balances running containers. And, through a DNS server embedded in the swarm, we can query every container running in the swarm.<\/span><\/p>\n<h4><span style=\"font-weight: 400\">iv. Load balancing<\/span><\/h4>\n<p><span style=\"font-weight: 400\">Basically, we can expose the ports for services to an external load balancer. Moreover, the swarm lets us specify how to distribute service containers between nodes, internally.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Docker Swarm &#8211; Nodes<\/span><\/h2>\n<p><span style=\"font-weight: 400\">In simple words, an instance of the Docker engine participating in the swarm is what we call a Node. We can also call it a Docker node. As a fact we can run one or more nodes on a single physical computer or cloud server. <\/span><\/p>\n<p><span style=\"font-weight: 400\">However, production swarm deployments involve Docker nodes which are distributed across multiple physical as well as cloud machines.<\/span><\/p>\n<p><strong>Do you know the Docker Use Cases<\/strong><\/p>\n<p><span style=\"font-weight: 400\">As a \u00a0process, we submit a service definition to a manager node, in order to deploy our application to a swarm. In addition, the manager node dispatches units of work which are known as tasks to worker nodes.<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Services and Tasks in Docker Swarm<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Generally, the definition of the tasks to execute on the manager or worker nodes is what we call Services. It is the primary root of user interaction with the swarm and also the central structure of the swarm system.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, we specify which container image to use and which commands to execute inside running containers, when we create a service.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Moreover, the swarm manager distributes a specific number of replica tasks among the nodes on the basis of the scale we set in the desired state, in the replicated services model. And, the swarm runs one task for the service on every available node in the cluster, for global services.<\/span><\/p>\n<p><span style=\"font-weight: 400\">While it comes to a task, it carries a <strong>Docker container<\/strong> and the commands to run inside the container. Also, it is the atomic scheduling unit of the swarm. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, according to the number of replicas set in the service scale, manager nodes assign tasks to worker nodes. As soon as a task is assigned to a node, then it cannot move to another node, so either it can only run on the assigned node or it will fail.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Load Balancing in Docker Swarm<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Simply, to expose the services we want to make available externally to the swarm, the swarm manager uses ingress load balancing. There is a flexibility that either we can configure a PublishedPort for the service or the swarm manager can automatically assign the service a PublishedPort. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, we can specify any unused port. Though, the swarm manager assigns the service a port in the 30000-32767 range, if we do not specify a port.<\/span><\/p>\n<p><span style=\"font-weight: 400\">In addition, the external components, like cloud load balancers, can access the service on the PublishedPort of any node in the cluster whether or not the node is currently running the task for the service.<\/span><\/p>\n<p><span style=\"font-weight: 400\">There is an internal DNS component in Swarm mode which automatically assigns each service in the swarm a DNS entry. Basically, in order to distribute requests among services within the cluster on the basis of the DNS name of the service, the swarm manager uses internal load balancing.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Docker Swarm Filters<\/span><\/h2>\n<p><span style=\"font-weight: 400\">There are five filters for scheduling containers in Swarm:<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>i. Constraint &#8211; <\/strong>The key\/value pairs associated with particular nodes is what we call Constraint. We also call them node tags. <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>ii. Affinity &#8211;<\/strong> The Affinity filter tells one container to run next to another based on an identifier, image or label in order to ensure containers run on the same network node.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>iii. Port &#8211;<\/strong> Basically ports represent a unique resource, with this filter. If somehow a container tries to run on a port which is already occupied, it will move to the next node in the cluster.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>iv. Dependency &#8211;<\/strong> If there is a time when containers depend on each other, then this filter schedules them on the same node.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>v. Health &#8212;<\/strong> When there is a time when a node is not functioning properly, then this filter will prevent scheduling containers on it.<\/span><\/p>\n<p>So, this was all about Docker Swarm Mode. Hope you like our explanation.<\/p>\n<h2><span style=\"font-weight: 400\">Conclusion<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Hence, we have seen whole about Docker Swarm mode in this article. However, if you want to ask any doubts regarding Docker swarm mode, feel free to ask through the comment section. Hope it helps!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we will cover up the complete concept of Docker Swarm Mode. Though, to understand Swarm mode well, it is important to know about Swarm also. So, we will discuss the meaning of Swarm.&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":37914,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16988],"tags":[17104,17108,17103,17109,17107,17105],"class_list":["post-37873","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker","tag-docker-swarm","tag-docker-swarm-filters","tag-docker-swarm-mode","tag-features-of-docker-swarm","tag-load-balancing-in-docker-swarm","tag-what-is-swarm"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Docker Swarm Mode - Features, Nodes and Filters - DataFlair<\/title>\n<meta name=\"description\" content=\"Docker Swarm Mode Tutorial - Features of Swarm in Docker, Nodes, Filters, Services and Tasks, Load Balancing in in Swarm Mode, Affinity, port, Depency\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/docker-swarm\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Docker Swarm Mode - Features, Nodes and Filters - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Docker Swarm Mode Tutorial - Features of Swarm in Docker, Nodes, Filters, Services and Tasks, Load Balancing in in Swarm Mode, Affinity, port, Depency\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/docker-swarm\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-02T05:26:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Swarm-Mode-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1202\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Docker Swarm Mode - Features, Nodes and Filters - DataFlair","description":"Docker Swarm Mode Tutorial - Features of Swarm in Docker, Nodes, Filters, Services and Tasks, Load Balancing in in Swarm Mode, Affinity, port, Depency","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:\/\/data-flair.training\/blogs\/docker-swarm\/","og_locale":"en_US","og_type":"article","og_title":"Docker Swarm Mode - Features, Nodes and Filters - DataFlair","og_description":"Docker Swarm Mode Tutorial - Features of Swarm in Docker, Nodes, Filters, Services and Tasks, Load Balancing in in Swarm Mode, Affinity, port, Depency","og_url":"https:\/\/data-flair.training\/blogs\/docker-swarm\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-12-02T05:26:28+00:00","og_image":[{"width":1202,"height":630,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Swarm-Mode-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/docker-swarm\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/docker-swarm\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Docker Swarm Mode &#8211; Features, Nodes and Filters","datePublished":"2018-12-02T05:26:28+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/docker-swarm\/"},"wordCount":1158,"commentCount":1,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/docker-swarm\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Swarm-Mode-01.jpg","keywords":["docker swarm","Docker Swarm Filters","docker swarm mode","Features of Docker Swarm","Load Balancing in Docker Swarm","what is swarm"],"articleSection":["Docker Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/docker-swarm\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/docker-swarm\/","url":"https:\/\/data-flair.training\/blogs\/docker-swarm\/","name":"Docker Swarm Mode - Features, Nodes and Filters - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/docker-swarm\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/docker-swarm\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Swarm-Mode-01.jpg","datePublished":"2018-12-02T05:26:28+00:00","description":"Docker Swarm Mode Tutorial - Features of Swarm in Docker, Nodes, Filters, Services and Tasks, Load Balancing in in Swarm Mode, Affinity, port, Depency","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/docker-swarm\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/docker-swarm\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/docker-swarm\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Swarm-Mode-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Swarm-Mode-01.jpg","width":1202,"height":630,"caption":"Docker Swarm Mode - Features, Nodes and Filters"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/docker-swarm\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Docker Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/docker\/"},{"@type":"ListItem","position":3,"name":"Docker Swarm Mode &#8211; Features, Nodes and Filters"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/37873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=37873"}],"version-history":[{"count":0,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/37873\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/37914"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=37873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=37873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=37873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}