{"id":8982,"date":"2024-07-25T08:53:28","date_gmt":"2024-07-25T08:53:28","guid":{"rendered":"https:\/\/www.webhi.com\/how-to\/?p=8982"},"modified":"2024-07-25T08:53:29","modified_gmt":"2024-07-25T08:53:29","slug":"setting-up-docker-swarm-cluster-on-ubuntu-linux","status":"publish","type":"post","link":"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/","title":{"rendered":"Setting up a Docker Swarm cluster on Ubuntu"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/07\/docker_swarm_en.jpg\" alt=\"Setting Up Docker Swarm on Ubuntu 18.04 20.04 22.04 ubuntu 24.04\" class=\"wp-image-9002\" srcset=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/07\/docker_swarm_en.jpg 1200w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/07\/docker_swarm_en-300x169.jpg 300w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/07\/docker_swarm_en-1024x576.jpg 1024w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/07\/docker_swarm_en-768x432.jpg 768w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/07\/docker_swarm_en-150x84.jpg 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"introduction\">Introduction<\/h3>\n\n\n\n<p>In all the world of containerization, Docker stands out as a very important technology that is fast revolutionizing the way in which applications will be developed, shipped, and deployed in the near future. Its features are many, but <strong>Docker Swarm<\/strong> is one of the standouts in this line that will provide powerful options for orchestrating and managing clusters in which Docker containers reside while maximizing hardware resources. Setting up a Docker Swarm cluster on Ubuntu is a brilliant and easy way to bring all the power of this orchestration tool to provide you with a robust, scalable, and fault-tolerant environment for your containerized application.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"understanding-docker-and-docker-swarm\">Understanding Docker and Docker Swarm<\/h3>\n\n\n\n<p>Docker is an open-source software that allows developers to automate the process of deploying applications in lightweight, portable containers. Such containers package an application with its dependencies, guaranteeing the consistency of an application on several development and production environments.<\/p>\n\n\n\n<p>On the contrary, Docker Swarm is the clustering and orchestration by Docker that is native. It converts a pool of Docker hosts into a single Docker engine virtually. In Docker Swarm, the deployment, management, and scaling of containerized applications across various nodes get done so that behaviors like high availability and fault tolerance can be ensured.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"prerequisites-for-docker-swarm-on-ubuntu\">Prerequisites for Docker Swarm on Ubuntu<\/h3>\n\n\n\n<p>Before moving on to setting up the steps, let&#8217;s check out a few of the prerequisites:<\/p>\n\n\n\n<ul>\n<li><strong>Ubuntu 18.04 or later<\/strong>: Any recent version of Ubuntu would fit to install Docker Swarm.<\/li>\n\n\n\n<li><strong>User with sudo privileges<\/strong>: The installation and setting up of Docker require administrative access.<\/li>\n\n\n\n<li><strong>Several Ubuntu machines<\/strong>: Although you can set up a single node Swarm, multiple machines make full use of Docker Swarm&#8217;s potentials.<\/li>\n\n\n\n<li><strong>Stable network connection<\/strong>: The nodes shall communicate reliably for the Swarm to function properly.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"installing-docker-on-ubuntu\">Installing Docker on Ubuntu<\/h3>\n\n\n\n<p>The first step in setting up a Docker Swarm cluster is to install Docker on all your Ubuntu nodes. Follow these steps:<\/p>\n\n\n\n<ol>\n<li><strong>Update your package database<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo apt-get update<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Install prerequisite packages<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common<\/code><\/pre>\n\n\n\n<ol start=\"3\">\n<li><strong>Add Docker\u2019s official GPG key<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo apt-key add -<\/code><\/pre>\n\n\n\n<ol start=\"4\">\n<li><strong>Add Docker\u2019s official repository<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo add-apt-repository \"deb [arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu $(lsb_release -cs) stable\"<\/code><\/pre>\n\n\n\n<ol start=\"5\">\n<li><strong>Update the package database again<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo apt-get update<\/code><\/pre>\n\n\n\n<ol start=\"6\">\n<li><strong>Install Docker<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo apt-get install docker-ce<\/code><\/pre>\n\n\n\n<ol start=\"7\">\n<li><strong>Verify the installation<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo systemctl status docker<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configuring-docker-for-swarm-mode\">Configuring Docker for Swarm Mode<\/h3>\n\n\n\n<p>With Docker installed, the next step is to configure it for Swarm mode. This involves initializing the Swarm on a manager node and then adding worker nodes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"setting-up-the-first-node\">Setting Up the First Node<\/h3>\n\n\n\n<ol>\n<li><strong>Initialize the Swarm on the manager node<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker swarm init --advertise-addr &lt;MANAGER-IP&gt;<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>&lt;MANAGER-IP&gt;<\/code>&nbsp;with the IP address of your manager node.<\/p>\n\n\n\n<ol start=\"2\">\n<li><strong>Note the join command<\/strong>: Docker will output a command that worker nodes need to join the Swarm. It looks something like this:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ docker swarm join --token &lt;SWARM-TOKEN&gt; &lt;MANAGER-IP&gt;:2377<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"creating-and-joining-additional-nodes\">Creating and Joining Additional Nodes<\/h3>\n\n\n\n<ol>\n<li><strong>On each worker node, run the join command<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker swarm join --token &lt;SWARM-TOKEN&gt; &lt;MANAGER-IP&gt;:2377<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>&lt;SWARM-TOKEN&gt;<\/code>&nbsp;and&nbsp;<code>&lt;MANAGER-IP&gt;<\/code>&nbsp;with the values from the previous step.<\/p>\n\n\n\n<ol start=\"2\">\n<li><strong>Verify the nodes are part of the Swarm on the manager node<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker node ls<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"deploying-services\">Deploying Services<\/h3>\n\n\n\n<p>With your Swarm cluster set up, you can now deploy services. Docker Swarm uses a declarative service model, where you define the desired state, and Swarm ensures that the cluster matches this state.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"creating-a-service-in-docker-swarm\">Creating a Service in Docker Swarm<\/h3>\n\n\n\n<ol>\n<li><strong>Create a simple service<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service create --name hello-world --replicas 3 alpine ping docker.com<\/code><\/pre>\n\n\n\n<p>This command creates a service named&nbsp;<code>hello-world<\/code>&nbsp;with three replicas running the&nbsp;<code>alpine<\/code>&nbsp;image.<\/p>\n\n\n\n<ol start=\"2\">\n<li><strong>Verify the service<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service ls<\/code><\/pre>\n\n\n\n<ol start=\"3\">\n<li><strong>Check the tasks associated with the service<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service ps hello-world<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"managing-services-in-docker-swarm\">Managing Services in Docker Swarm<\/h3>\n\n\n\n<ol>\n<li><strong>Scale the service up or down<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service scale hello-world=5<\/code><\/pre>\n\n\n\n<p>This command scales the&nbsp;<code>hello-world<\/code>&nbsp;service to 5 replicas.<\/p>\n\n\n\n<ol start=\"2\">\n<li><strong>Update the service<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service update --image alpine:latest hello-world<\/code><\/pre>\n\n\n\n<ol start=\"3\">\n<li><strong>Remove the service<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service rm hello-world<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"networking-in-docker-swarm\">Networking in Docker Swarm<\/h3>\n\n\n\n<p>Docker Swarm provides several networking options to facilitate communication between containers across different nodes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"overlay-network\">Overlay Network<\/h3>\n\n\n\n<ol>\n<li><strong>Create an overlay network<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker network create -d overlay my-overlay<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Deploy a service on the overlay network<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service create --name my-service --network my-overlay alpine ping docker.com<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ingress-network\">Ingress Network<\/h3>\n\n\n\n<p>The ingress network is used for routing external traffic to the appropriate service in the Swarm.<\/p>\n\n\n\n<ol>\n<li><strong>Publish a service on a specific port<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service create --name web-service --publish published=80,target=80 nginx<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Verify the service is accessible<\/strong>: Access the manager node\u2019s IP on port 80 in your web browser.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"scaling-services\">Scaling Services<\/h3>\n\n\n\n<p>Docker Swarm makes it easy to scale your services to handle increased load.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"increasing-and-decreasing-service-replicas\">Increasing and Decreasing Service Replicas<\/h3>\n\n\n\n<ol>\n<li><strong>Scale a service up<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service scale web-service=10<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Scale a service down<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service scale web-service=2<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"load-balancing\">Load Balancing<\/h3>\n\n\n\n<p>Docker Swarm automatically load balances traffic across the replicas of a service.<\/p>\n\n\n\n<ol>\n<li><strong>Verify load balancing<\/strong>: Access your service multiple times via the manager node\u2019s IP to see traffic distributed across different replicas.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"handling-failures\">Handling Failures<\/h3>\n\n\n\n<p>Docker Swarm is designed to handle node failures gracefully, ensuring your services remain available.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"high-availability\">High Availability<\/h3>\n\n\n\n<p>Docker Swarm can maintain service availability by redistributing tasks from failed nodes to healthy ones.<\/p>\n\n\n\n<ol>\n<li><strong>Simulate a node failure<\/strong>: Shut down a worker node and observe how Docker Swarm reallocates its tasks.<\/li>\n\n\n\n<li><strong>Check service status<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service ps web-service<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"rolling-updates\">Rolling Updates<\/h3>\n\n\n\n<p>Docker Swarm allows you to update services with minimal downtime.<\/p>\n\n\n\n<ol>\n<li><strong>Update a service<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service update --image nginx:latest web-service<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Monitor the update<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service ps web-service<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"security-considerations\">Security Considerations<\/h3>\n\n\n\n<p>Security is a crucial aspect of any production environment. Docker Swarm offers various features to secure your cluster.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"securing-communication\">Securing Communication<\/h3>\n\n\n\n<ol>\n<li><strong>Enable TLS encryption<\/strong>: Docker Swarm uses TLS for secure communication between nodes by default.<\/li>\n\n\n\n<li><strong>Verify TLS certificates<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker info | grep -i \"tls\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"managing-user-access\">Managing User Access<\/h3>\n\n\n\n<ol>\n<li><strong>Create a Docker Swarm user<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo useradd -m dockeruser<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Add the user to the Docker group<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo usermod -aG docker dockeruser<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"monitoring-and-maintenance\">Monitoring and Maintenance<\/h3>\n\n\n\n<p>Regular monitoring and maintenance are essential for the smooth operation of your Docker Swarm cluster.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"monitoring-tools\">Monitoring Tools<\/h3>\n\n\n\n<ol>\n<li><strong>Use Docker\u2019s built-in monitoring<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker stats<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Integrate third-party tools<\/strong>: Consider tools like Prometheus and Grafana for advanced monitoring and visualization.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"regular-maintenance-practices\">Regular Maintenance Practices<\/h3>\n\n\n\n<ol>\n<li><strong>Update Docker and your services regularly<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo apt-get update &amp;&amp; sudo apt-get upgrade\n$ sudo docker service update --image &lt;new-image&gt; &lt;service-name&gt;<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Clean up unused resources<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker system prune<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"advanced-configuration\">Advanced Configuration<\/h3>\n\n\n\n<p>For advanced users, Docker Swarm offers various configuration options to tailor the cluster to specific needs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-docker-compose-with-docker-swarm\">Using Docker Compose with Docker Swarm<\/h3>\n\n\n\n<ol>\n<li><strong>Create a&nbsp;<code>docker-compose.yml<\/code>&nbsp;file<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">version: '3'\nservices:\n   web:\n      image: nginx\n      deploy:\n      replicas: 3\n      update_config:\n         parallelism: 2\n         delay: 10s<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Deploy the stack<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker stack deploy -c docker-compose.yml mystack<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"persistent-storage-with-docker-swarm\">Persistent Storage with Docker Swarm<\/h3>\n\n\n\n<ol>\n<li><strong>Create a Docker volume<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker volume create my-volume<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Use the volume in a service<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service create --name my-service --mount source=my-volume,target=\/app nginx<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"troubleshooting-common-issues\">Troubleshooting Common Issues<\/h3>\n\n\n\n<p>Despite its robustness, you may encounter issues with Docker Swarm. Here\u2019s how to troubleshoot common problems.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"connectivity-issues\">Connectivity Issues<\/h3>\n\n\n\n<ol>\n<li><strong>Check the network status<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker network ls<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Inspect a specific network<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker network inspect &lt;network-name&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"resource-allocation-problems\">Resource Allocation Problems<\/h3>\n\n\n\n<ol>\n<li><strong>Check resource usage<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker stats<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Adjust service resources<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service update --limit-cpu 0.5 --limit-memory 512M &lt;service-name&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h3>\n\n\n\n<p>Setting up a Docker Swarm cluster on Ubuntu is a powerful way to manage containerized applications with high availability and scalability. By following the steps outlined in this guide, you can harness the full potential of Docker Swarm, ensuring your applications are robust, secure, and easy to maintain. Whether you&#8217;re deploying a small project or a large-scale application, Docker Swarm provides the tools and flexibility needed to meet your requirements.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faqs\">FAQs<\/h3>\n\n\n\n<p><strong>How do I update a service in Docker Swarm?<\/strong><\/p>\n\n\n\n<p>To update a service in Docker Swarm, use the&nbsp;<code>docker service update<\/code>&nbsp;command. For example, to update the image of a service, you can run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo docker service update --image &lt;new-image&gt; &lt;service-name&gt;<\/code><\/pre>\n\n\n\n<p>This command will perform a rolling update, ensuring minimal downtime.<\/p>\n\n\n\n<p><strong>What are the benefits of using Docker Swarm?<\/strong><\/p>\n\n\n\n<p>Docker Swarm provides several benefits, including simplified container orchestration, high availability, scalability, and load balancing. It allows you to manage a cluster of Docker engines as a single entity, making it easier to deploy and manage services.<\/p>\n\n\n\n<p><strong>Can Docker Swarm handle large-scale deployments?<\/strong><\/p>\n\n\n\n<p>Yes, Docker Swarm is designed to handle large-scale deployments. It can manage thousands of nodes and containers, ensuring high availability and fault tolerance. Its architecture allows for efficient scaling and resource utilization.<\/p>\n\n\n\n<p><strong>How does Docker Swarm ensure service availability?<\/strong><\/p>\n\n\n\n<p>Docker Swarm ensures service availability through its high availability and fault-tolerance mechanisms. It automatically redistributes tasks from failed nodes to healthy ones and uses load balancing to distribute traffic across service replicas.<\/p>\n\n\n\n<p><strong>Is Docker Swarm secure for production environments?<\/strong><\/p>\n\n\n\n<p>Yes, Docker Swarm is secure for production environments. It uses TLS encryption for secure communication between nodes and offers various security features such as role-based access control and secret management.<\/p>\n\n\n\n<p><strong>How do I monitor a Docker Swarm cluster?<\/strong><\/p>\n\n\n\n<p>You can monitor a Docker Swarm cluster using Docker&#8217;s built-in tools such as&nbsp;<code>docker stats<\/code>&nbsp;and&nbsp;<code>docker service ls<\/code>. For advanced monitoring, you can integrate third-party tools like Prometheus and Grafana to collect and visualize metrics from your Swarm cluster.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"inbound-and-outbound-links\">Inbound and Outbound Links<\/h3>\n\n\n\n<p><strong>Inbound Links:<\/strong><\/p>\n\n\n\n<ul>\n<li><a href=\"#understanding-docker-and-docker-swarm\">Understanding Docker<\/a><\/li>\n\n\n\n<li><a href=\"#installing-docker-on-ubuntu\">Installing Docker on Ubuntu<\/a><\/li>\n\n\n\n<li><a href=\"#deploying-services\">Deploying Services<\/a><\/li>\n<\/ul>\n\n\n\n<p><strong>Outbound Links:<\/strong><\/p>\n\n\n\n<ul>\n<li><a href=\"https:\/\/docs.docker.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Docker Documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/prometheus.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">Prometheus Monitoring<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/grafana.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Grafana<\/a><\/li>\n<\/ul>\n\n\n\n<p>By following these comprehensive steps and utilizing the powerful features of Docker Swarm, you can ensure that your containerized applications are efficiently managed and highly available. Docker Swarm on Ubuntu provides a reliable and scalable solution for modern application deployment, making it an essential tool for developers and system administrators alike.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In all the world of containerization, Docker stands out as a very important technology that is fast revolutionizing the way in which applications will be developed, shipped, and deployed in the near future. Its features are many, but Docker Swarm is one of the standouts in this line that will provide powerful options for ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[182],"tags":[],"yoast_head":"\n<title>Setting up a Docker Swarm cluster on Ubuntu - WebHi Tutorials &amp; Documentations<\/title>\n<meta name=\"description\" content=\"Learn how to set up a Docker Swarm cluster on Ubuntu 18.04 \/ 20.04 &amp; 22.04 and above for efficient container management and deployment.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setting up a Docker Swarm cluster on Ubuntu - WebHi Tutorials &amp; Documentations\" \/>\n<meta property=\"og:description\" content=\"Learn how to set up a Docker Swarm cluster on Ubuntu 18.04 \/ 20.04 &amp; 22.04 and above for efficient container management and deployment.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"WebHi Tutorials &amp; Documentations\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webhi.technology\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-25T08:53:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-25T08:53:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/07\/docker_swarm_en.jpg\" \/>\n<meta name=\"author\" content=\"webhi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@WebHiTechnology\" \/>\n<meta name=\"twitter:site\" content=\"@WebHiTechnology\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webhi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/\"},\"author\":{\"name\":\"webhi\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54\"},\"headline\":\"Setting up a Docker Swarm cluster on Ubuntu\",\"datePublished\":\"2024-07-25T08:53:28+00:00\",\"dateModified\":\"2024-07-25T08:53:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/\"},\"wordCount\":1355,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\"},\"articleSection\":[\"Virtualization &amp; Cloud computing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/\",\"name\":\"Setting up a Docker Swarm cluster on Ubuntu - WebHi Tutorials &amp; Documentations\",\"isPartOf\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#website\"},\"datePublished\":\"2024-07-25T08:53:28+00:00\",\"dateModified\":\"2024-07-25T08:53:29+00:00\",\"description\":\"Learn how to set up a Docker Swarm cluster on Ubuntu 18.04 \/ 20.04 & 22.04 and above for efficient container management and deployment.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webhi.com\/how-to\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setting up a Docker Swarm cluster on Ubuntu\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#website\",\"url\":\"https:\/\/www.webhi.com\/how-to\/\",\"name\":\"WebHi Tutorials &amp; Documentations\",\"description\":\"System administration and knowledge base\",\"publisher\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webhi.com\/how-to\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\",\"name\":\"WebHi Technology\",\"url\":\"https:\/\/www.webhi.com\/how-to\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png\",\"contentUrl\":\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png\",\"width\":288,\"height\":95,\"caption\":\"WebHi Technology\"},\"image\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webhi.technology\",\"https:\/\/twitter.com\/WebHiTechnology\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54\",\"name\":\"webhi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1780005063\",\"contentUrl\":\"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1780005063\",\"caption\":\"webhi\"},\"sameAs\":[\"https:\/\/www.webhi.com\/how-to\"],\"url\":\"https:\/\/www.webhi.com\/how-to\/author\/webhi\/\"}]}<\/script>\n","yoast_head_json":{"title":"Setting up a Docker Swarm cluster on Ubuntu - WebHi Tutorials &amp; Documentations","description":"Learn how to set up a Docker Swarm cluster on Ubuntu 18.04 \/ 20.04 & 22.04 and above for efficient container management and deployment.","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:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/","og_locale":"en_US","og_type":"article","og_title":"Setting up a Docker Swarm cluster on Ubuntu - WebHi Tutorials &amp; Documentations","og_description":"Learn how to set up a Docker Swarm cluster on Ubuntu 18.04 \/ 20.04 & 22.04 and above for efficient container management and deployment.","og_url":"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/","og_site_name":"WebHi Tutorials &amp; Documentations","article_publisher":"https:\/\/www.facebook.com\/webhi.technology","article_published_time":"2024-07-25T08:53:28+00:00","article_modified_time":"2024-07-25T08:53:29+00:00","og_image":[{"url":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/07\/docker_swarm_en.jpg"}],"author":"webhi","twitter_card":"summary_large_image","twitter_creator":"@WebHiTechnology","twitter_site":"@WebHiTechnology","twitter_misc":{"Written by":"webhi","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/#article","isPartOf":{"@id":"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/"},"author":{"name":"webhi","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54"},"headline":"Setting up a Docker Swarm cluster on Ubuntu","datePublished":"2024-07-25T08:53:28+00:00","dateModified":"2024-07-25T08:53:29+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/"},"wordCount":1355,"commentCount":0,"publisher":{"@id":"https:\/\/www.webhi.com\/how-to\/#organization"},"articleSection":["Virtualization &amp; Cloud computing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/","url":"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/","name":"Setting up a Docker Swarm cluster on Ubuntu - WebHi Tutorials &amp; Documentations","isPartOf":{"@id":"https:\/\/www.webhi.com\/how-to\/#website"},"datePublished":"2024-07-25T08:53:28+00:00","dateModified":"2024-07-25T08:53:29+00:00","description":"Learn how to set up a Docker Swarm cluster on Ubuntu 18.04 \/ 20.04 & 22.04 and above for efficient container management and deployment.","breadcrumb":{"@id":"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.webhi.com\/how-to\/setting-up-docker-swarm-cluster-on-ubuntu-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webhi.com\/how-to\/"},{"@type":"ListItem","position":2,"name":"Setting up a Docker Swarm cluster on Ubuntu"}]},{"@type":"WebSite","@id":"https:\/\/www.webhi.com\/how-to\/#website","url":"https:\/\/www.webhi.com\/how-to\/","name":"WebHi Tutorials &amp; Documentations","description":"System administration and knowledge base","publisher":{"@id":"https:\/\/www.webhi.com\/how-to\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webhi.com\/how-to\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webhi.com\/how-to\/#organization","name":"WebHi Technology","url":"https:\/\/www.webhi.com\/how-to\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/","url":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png","contentUrl":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png","width":288,"height":95,"caption":"WebHi Technology"},"image":{"@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webhi.technology","https:\/\/twitter.com\/WebHiTechnology"]},{"@type":"Person","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54","name":"webhi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/image\/","url":"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1780005063","contentUrl":"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1780005063","caption":"webhi"},"sameAs":["https:\/\/www.webhi.com\/how-to"],"url":"https:\/\/www.webhi.com\/how-to\/author\/webhi\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/8982"}],"collection":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/comments?post=8982"}],"version-history":[{"count":7,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/8982\/revisions"}],"predecessor-version":[{"id":9013,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/8982\/revisions\/9013"}],"wp:attachment":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/media?parent=8982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/categories?post=8982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/tags?post=8982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}