{"id":726,"date":"2026-07-26T23:46:48","date_gmt":"2026-07-26T23:46:48","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=726"},"modified":"2026-07-26T23:46:48","modified_gmt":"2026-07-26T23:46:48","slug":"setting-up-docker-swarm-cluster-vps-high-availability","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/","title":{"rendered":"Setting Up a Docker Swarm Cluster on VPS for High Availability"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Container orchestration transforms a single VPS into the foundation of a highly available application cluster. Docker Swarm, included natively with Docker, provides orchestration with minimal overhead and no additional licensing costs. This guide walks through setting up a three-node Docker Swarm cluster across multiple VPS instances for production-grade high availability. For VPS plans with enough resources to run a Swarm cluster, check <a href=\"https:\/\/virtualserversvps.com\/#providers\">our provider comparison<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Three VPS instances (1 vCPU, 2 GB RAM minimum each)<\/li>\n<li>Ubuntu 22.04 or 24.04 LTS on all nodes<\/li>\n<li>Private networking enabled between nodes (same provider VLAN or VPN)<\/li>\n<li>Open ports: 2377\/tcp (cluster management), 7946\/tcp+udp (node communication), 4789\/udp (overlay network)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Install Docker on All Nodes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following on every VPS in the cluster:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Remove old packages\nsudo apt remove -y docker docker-engine docker.io containerd runc\n\n# Install dependencies\nsudo apt update\nsudo apt install -y ca-certificates curl gnupg\n\n# Add Docker GPG key\nsudo install -m 0755 -d \/etc\/apt\/keyrings\ncurl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo gpg --dearmor -o \/etc\/apt\/keyrings\/docker.gpg\nsudo chmod a+r \/etc\/apt\/keyrings\/docker.gpg\n\n# Add repository\necho \"deb [arch=$(dpkg --print-architecture) signed-by=\/etc\/apt\/keyrings\/docker.gpg] https:\/\/download.docker.com\/linux\/ubuntu $(lsb_release -cs) stable\" | sudo tee \/etc\/apt\/sources.list.d\/docker.list &gt; \/dev\/null\n\n# Install Docker\nsudo apt update\nsudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin\n\n# Verify installation\nsudo docker --version\nsudo docker run hello-world<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Initialize the Swarm Cluster<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Choose one node as the <strong>manager<\/strong> (the first node that initializes the cluster):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># On manager node (use private IP if available)\nsudo docker swarm init --advertise-addr 10.0.0.1\n\n# Output contains the join token for worker nodes\n# Copy the full output - it looks like:\n#   docker swarm join --token SWMTKN-1-xxxxx 10.0.0.1:2377<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To add manager redundancy, promote additional manager nodes. Docker Swarm recommends 3 or 5 managers for production:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># On manager node, get the manager join token\nsudo docker swarm join-token manager\n\n# On the second manager node, run the join command from above output\nsudo docker swarm join --token SWMTKN-1-xxxxx 10.0.0.1:2377<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Add Worker Nodes<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># On manager, get the worker join token\nsudo docker swarm join-token worker\n\n# On each worker VPS\nsudo docker swarm join --token SWMTKN-1-xxxxx 10.0.0.1:2377<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Verify the Cluster<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># On any manager node\nsudo docker node ls\n\n# Expected output:\n# ID          HOSTNAME   STATUS   AVAILABILITY   MANAGER STATUS   ENGINE VERSION\n# abc... *    node-1     Ready    Active         Reachable        24.0.7\n# def...      node-2     Ready    Active         Leader           24.0.7\n# ghi...      node-3     Ready    Active                          24.0.7<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Deploy a Highly Available Service<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Deploy an Nginx service with 3 replicas distributed across the cluster:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Create an overlay network for the service\nsudo docker network create --driver overlay --attachable app-network\n\n# Deploy the service with 3 replicas\nsudo docker service create   --name web   --replicas 3   --network app-network   --publish published=80,target=80   nginx:alpine\n\n# Verify the service\nsudo docker service ls\nsudo docker service ps web<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Test High Availability<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Simulate a node failure and verify automatic rescheduling:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># On the manager, drain a worker node\nsudo docker node update --availability drain node-3\n\n# Check that Swarm rescheduled the containers to other nodes\nsudo docker service ps web\n\n# Bring the node back\nsudo docker node update --availability active node-3<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 7: Rolling Updates and Rollbacks<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Swarm handles zero-downtime deployments natively:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Update the image with rolling update (updates 1 replica at a time)\nsudo docker service update --image nginx:1.25 --update-parallelism 1 --update-delay 10s web\n\n# Monitor the update\nsudo docker service ps web\n\n# Rollback if something goes wrong\nsudo docker service rollback web<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 8: Add a Load Balancer (Traefik)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For production traffic, use Traefik as a reverse proxy that auto-discovers Swarm services:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Deploy Traefik as a global service\nsudo docker service create   --name traefik   --constraint 'node.role == manager'   --publish published=443,target=443   --publish published=80,target=80   --mount type=bind,source=\/var\/run\/docker.sock,target=\/var\/run\/docker.sock   --network app-network   traefik:v3.0   --api.insecure=false   --providers.docker=true   --providers.docker.swarmmode=true   --entrypoints.websecure.address=:443   --entrypoints.web.address=:80<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 9: Persistent Storage with NFS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Stateful services need shared storage. Mount an NFS share on all nodes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># On all nodes (assuming an NFS server at 10.0.0.100)\nsudo apt install -y nfs-common\nsudo mkdir -p \/mnt\/shared\nsudo mount -t nfs 10.0.0.100:\/exports\/shared \/mnt\/shared\n\n# Add to \/etc\/fstab for persistence\necho \"10.0.0.100:\/exports\/shared \/mnt\/shared nfs defaults 0 0\" | sudo tee -a \/etc\/fstab<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 10: Monitoring the Swarm<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Check node resource usage across the cluster\nsudo docker node ps $(sudo docker node ls -q)\n\n# View service logs\nsudo docker service logs --tail 50 web\n\n# Real-time container stats across the cluster\nsudo docker stats --no-stream<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Docker Swarm turns multiple VPS instances into a unified, highly available application platform with minimal overhead. Unlike Kubernetes, Swarm is simpler to set up and manage on small clusters (3\u201310 nodes), making it an excellent choice for VPS-based production deployments. With rolling updates, automatic failover, and built-in load balancing, your applications stay online even when individual nodes fail. Start with 3 manager nodes for a fault-tolerant control plane, then add worker nodes as your workload grows.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Container orchestration transforms a single VPS into the foundation of a highly available application cluster. Docker Swarm, included natively with Docker, provides orchestration with minimal overhead and no additional licensing&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-726","post","type-post","status-publish","format-standard","hentry","category-vps-guides-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Setting Up a Docker Swarm Cluster on VPS for High Availability - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/\" \/>\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 VPS for High Availability\" \/>\n<meta property=\"og:description\" content=\"Setting Up a Docker Swarm Cluster on VPS for High Availability\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-26T23:46:48+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/\",\"name\":\"Setting Up a Docker Swarm Cluster on VPS for High Availability - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-07-26T23:46:48+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setting Up a Docker Swarm Cluster on VPS for High Availability\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Setting Up a Docker Swarm Cluster on VPS for High Availability - Virtual Servers VPS Blog","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:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/","og_locale":"en_US","og_type":"article","og_title":"Setting Up a Docker Swarm Cluster on VPS for High Availability","og_description":"Setting Up a Docker Swarm Cluster on VPS for High Availability","og_url":"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-07-26T23:46:48+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/","url":"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/","name":"Setting Up a Docker Swarm Cluster on VPS for High Availability - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-07-26T23:46:48+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/setting-up-docker-swarm-cluster-vps-high-availability\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Setting Up a Docker Swarm Cluster on VPS for High Availability"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=726"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/726\/revisions"}],"predecessor-version":[{"id":727,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/726\/revisions\/727"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}