Hosting a Docker Swarm on a VPS: Definitive Guide

The first thing to understand about Swarm is that it’s not a separate software for you to install somewhere. It’s already built into Docker. You simply turn it on (activate it with docker swarm init). Docker’s Swarm mode has nodes, like bees. A node can be a manager, a worker, or both. Managers make scheduling decisions and maintain cluster state via the Raft consensus algorithm. The worker nodes run the actual containers.

If you are reading about Docker Swarm, then chances are you already know about Kubernetes. We’ll be honest upfront: the only reason why you might choose Swarm over Kubernetes is operational simplicity. If you’re okay with (and actually need) more advanced scheduling and a larger ecosystem, Kubernetes is a must.

That being said, let’s take a look at what Swarm can do for you. Loose containers are what you’re likely coming from, so here are the key advantages:

  • Swarm is self-healing. A failed task gets rescheduled automatically.
  • It features rolling updates with configurable rollback.
  • There’s declarative desired-state management, so if you say “I want 5 replicas,” Swarm keeps 5 running.

All this is handled with the help of services, tasks, and the routing mesh.

  • Services: The definition of what to run and how many replicas.
  • Tasks: Individual container instances of a service.
  • Routing Mesh: Built-in load balancing that routes requests to any node, which forwards to a container running the service, even if that container isn’t on the node that received the request.

Minimum Cluster Architecture

If you’re going with a DIY/raw VPS setup, there are some important things to keep in mind: manager and worker counts, per-node resource allocation, and network requirements.

Manager node count should always be odd (1, 3, or 5) because of how Raft consensus tolerates failures: a 3-manager cluster tolerates 1 manager going down, a 5-manager cluster tolerates 2. An even number doesn’t add fault tolerance and just adds overhead.

Of course, a single manager isn’t going to be very helpful in almost any practical situation (unless if it’s a toy setup or some type of experiment). Docker’s own recommendation is a minimum of 3 managers to ensure proper production fault tolerance. If you only have a single manager, you have no failover if/when that manager fails.

As there’s no min/max limit on the workers you can have per manager, the worker nodes are independent of how many managers you got. The worker count can scale up based on your workload.

Speaking of per-node resource allocation, keep in mind that workers are the main resource consumers. The managers are handling scheduling, etc.—which is cheaper, so to speak, in terms of resources required. The workers are actually running your app and the various processes, so they consume the bulk of resources vs. managers handling scheduling and consensus. Your key production workers need to be sized to the actual containerized workloads—this is the same RAM/CPU logic as any other VPS sizing task.

Lastly, there are network deliberations as well. Swarm needs specific ports open between nodes for cluster communication. This includes TCP 2377 (cluster management), TCP/UDP 7946 (node discovery/gossip), and UDP 4789 (overlay network data path, VXLAN).

Networking & Load Balancing

Swarm’s routing mesh means every node in the cluster can accept traffic on a published port and route it internally to wherever the container actually lives. You don’t need to know or care which node a container landed on to reach it. Overlay networks let containers on different physical hosts talk to each other as if on the same LAN, this is the mechanism that makes a multi-VPS swarm function as one logical unit.

For production, an external load balancer or reverse proxy (Traefik, Nginx, HAProxy) in front of the swarm is standard practice, worth noting since it’s a step often skipped in “getting started” guides but expected in real deployments.

Managed hardware firewall (control panel-level) is can be used to restrict the swarm’s inter-node ports to just the swarm’s own IPs, rather than leaving 2377/7946/4789 open to the internet.

Storage Considerations

Containers are ephemeral by design, anything written inside a container disappears when it’s removed unless persisted. For Swarm specifically, the relevant fact is that a service’s tasks can be rescheduled to any node, so local-disk volumes don’t reliably follow the container.

There are two main ways here:

  1. Bind mounds or local volumes are simplest but tied to one node. If you need stateless or single-node-pinned services, these will work just fine.
  2. A shared or networked storage layer is preferred for stateful services that need to move freely between nodes.

Also, one thing to keep in mind is that the faster the storage, the better your experience will be (and the smoother the application will run, naturally). That’s why NVMe or Flash storage is highly recommended. It’s also our very own standard: our VPS plans come with fast NVMe/Flash storage by default. Faster storage matters the most for any database or heavy-write service running inside the swarm. As for backups, a SATA disk is standard. Live container storage should ideally be something faster than regular SATA.

Security & Passwords

Swarm has built-in mutual TLS between nodes by default for manager/worker communication. It’s a genuine built-in advantage over some DIY container networking setups.

Docker secrets (docker secret create) is Swarm’s native mechanism for handling passwords, API keys, and certificates without baking them into images or exposing them in plain environment variables. This is a key good practice you should always use.

Also, standard hardening advice applies.

  • Keep the Docker engine patched.
  • Restrict swarm management ports at the firewall to only the nodes that need them.
  • Avoid running containers as root inside the container where avoidable.
  • Backup the container data as well as the swarm’s own state.
quote
Neil

PROMO CODES

Toggle VPS Promo Code

Enter the promo codes below on the checkout page.

80% OFF FIRST MONTHLY*
80% off your first monthly payment.
Code: 80OFF

30% OFF FIRST ANNUAL*
30% off your first annual or semi-annual payment. You can save hundreds.
Code: VPSHOST30

* These offers may be used once per customer for new VPS orders only.