Skip to content

How to run Docker Compose across multiple servers

Nick Potts, who builds Ployz. Published , updated .

TL;DR: Docker Compose runs on one server, so going multi-server means picking a second tool. The choice comes down to one question: can containers on different servers talk to each other privately?

  • Pick Docker contexts if you want the same Compose stack on several independent servers. It's free and uses your file unchanged.
  • Pick WireGuard plus Compose on each server if you want one app across servers with boring tools, and you're fine being the orchestrator.
  • Pick Docker Swarm if you want replicas and a cross-host network from Docker itself, and will run a registry and three managers.
  • Pick Kamal if you're on Rails or like a config file, and will put a load balancer in front.
  • Pick K3s or Nomad if you already know them or expect dozens of servers.
  • Pick Ployz if you want servers on one encrypted network, services reaching each other by name, a load balancer on every server, and a coding agent that can deploy to them, and you don't need your Compose file imported.

Docker Compose is a file format and a client that starts a set of containers on one Docker daemon. Docker's own docs say "Compose supports production deployments on single hosts" (Compose overview), and for anything bigger they point you to Swarm (Compose in production).

If you're still on one server and it isn't full, the cheapest option is a bigger server. I'd do that first. Everything below is for when one box really isn't enough, or when you want a second one so a single machine isn't your whole business.

How do the options compare?

"Private network" means a container on server A can reach a container on server B without you exposing ports to the internet.

OptionUses your Compose file?Private network between serversLoad balancing across serversServers you needExtra parts to run
Docker contextsYes, unchangedNoNo, add your own1+None
Docker SwarmYes, legacy v3 formatYes, overlay (unencrypted by default)Yes, routing mesh3 managers for fault toleranceRegistry, open ports 2377/7946/4789
WireGuard or Tailscale + Compose per serverYes, one per serverYes, encryptedNo, add your own1+The VPN, a load balancer
KamalNo, its own deploy.ymlNoNo, add your own1+Registry
NomadNo, its own job filesVia Consul or templatesAdd your own (e.g. Traefik)3 to 5 servers recommendedNomad servers, often Consul
K3sNo, Kubernetes manifestsYes, Flannel (WireGuard optional)Yes, via Kubernetes1, or 3 for HAKubernetes itself
PloyzNo, services set up separatelyYes, encrypted WireGuardYes, Caddy on every server1+None to rent

Why can't Docker Compose span servers?

Compose talks to one Docker daemon at a time. It creates containers, networks and volumes on that daemon, and the network it makes is a bridge network that only exists on that machine. You can point Compose at several remote daemons, but each run is a separate single-host deployment, and nothing joins them up.

That's a design choice. The parts that make multi-server hard (scheduling containers onto machines, a network that spans hosts, moving traffic when a server dies) belong to an orchestrator. Docker's answer was Swarm mode; Kubernetes, Nomad and K3s are the others.

What Compose does give you is remote control. Set DOCKER_HOST and "all the normal docker compose commands work with no further configuration" (Compose in production). Docker contexts make that tidy.

Docker contexts: the same stack on several servers

A context stores the connection details for one Docker daemon, including an SSH address, and lets you "switch the daemon your docker CLI connects to" (docker context create). Create one context per server and run docker compose up once per context. There's no agent, cluster or registry.

A worked example: a web app on two servers, with Postgres on a third. The SSH form comes from Docker's daemon access docs, and the SSH user needs access to the Docker socket on each server.

# One context per server (SSH keys already set up)
docker context create web1 --docker "host=ssh://deploy@203.0.113.10"
docker context create web2 --docker "host=ssh://deploy@203.0.113.11"
docker context create db1  --docker "host=ssh://deploy@203.0.113.20"

# Postgres on its own server
DOCKER_CONTEXT=db1 docker compose -f db.compose.yaml up -d

# The same app stack on both web servers
for ctx in web1 web2; do
  DOCKER_CONTEXT=$ctx docker compose -f app.compose.yaml up -d --build
done

DOCKER_CONTEXT "overrides the context set with docker context use" (Docker contexts), so the loop doesn't change your default. With --build, each server builds the image itself, so there's no registry.

Here's the catch, in the app file:

services:
  web:
    build: .
    ports:
      - "8080:3000"
    environment:
      # Not "db:5432". The db service lives on another server's network.
      DATABASE_URL: postgres://app:secret@203.0.113.20:5432/app

On one server you'd write db:5432. Across servers there's no shared network, so the web servers reach Postgres by IP, and Postgres has to listen on a port other machines can reach. On a public IP that's a database on the internet, guarded by a firewall rule and a password. You also still need something in front of web1 and web2 to split traffic.

Where it wins: "same stack, several independent servers", like one copy per customer or per region. Where it falls short: for one app spread across servers, it solves only the easy half.

Docker Swarm: Compose, but across servers

Swarm is built into Docker Engine. You turn a few servers into a swarm and run docker stack deploy --compose-file compose.yaml (stack deploy tutorial). You get replicas, an overlay network between hosts and a routing mesh.

What people find out late, from Docker's docs:

  • Your Compose file may not work as-is. docker stack deploy uses "the legacy Compose file version 3 format", and "the latest format, defined by the Compose specification isn't compatible" with it. build is ignored, so you push images first (stack deploy).
  • You need a registry. "Because a swarm consists of multiple Docker Engines, a registry is required to distribute images to all of them" (same page).
  • Three ports between nodes: 2377/tcp for the control plane, 7946 tcp and udp between nodes, 4789/udp for overlay traffic (overlay networks).
  • Overlay traffic is unencrypted by default. --opt encrypted turns on IPsec, which Docker warns "imposes a non-negligible performance penalty" (same page).
  • Quorum. "Raft requires a majority of managers." Three managers survive one failure, five survive two. Lose quorum and running tasks keep going, but nothing "can be started, stopped, moved, or updated" (Swarm admin guide).

Swarm isn't dead. Docker separates Swarm mode from "Docker Classic Swarm which is no longer actively developed" (Swarm mode), and Mirantis said in July 2025 that "Swarm will be fully supported through at least 2030" (Mirantis).

Where it wins: the closest thing to Compose across servers, from Docker itself. Where it falls short: I think the real cost is that fewer people run it, so when it misbehaves you're reading old GitHub issues.

WireGuard or Tailscale plus Compose on each server

Put every server on a private WireGuard network, or on Tailscale, then run a normal Compose stack on each server and bind ports to the private address. Postgres listens on 10.0.0.3:5432, not on the internet.

In practice:

  • Each server gets a private address. Tailscale's free Personal plan allows up to 6 users and is for personal, non-commercial use (Tailscale pricing); for a business, plain WireGuard is free and a little more work.
  • In Compose, publish database ports on the private IP only, for example "10.0.0.3:5432:5432".
  • Service names don't resolve across servers. You use private IPs, or run your own DNS on the VPN.
  • For traffic, you run Caddy, nginx or HAProxy on one server, or rent a load balancer.

Where it wins: every piece is boring and you can debug each one alone. I like it more than Swarm for small teams. Where it falls short: you're the orchestrator. If a server dies, nothing moves its containers, and you update IPs by hand.

Kamal: a config file and SSH

Kamal, from 37signals, is multi-host by design. You list servers in config/deploy.yml, and one kamal deploy pushes your image to a registry and rolls it out over SSH, with zero-downtime switches through kamal-proxy.

  • Load balancing is yours: "If you're running multiple servers, you need to put a load balancer in front of them" (Kamal installation). Let's Encrypt may not be an option "if you are running from more than one host" (proxy config), so you usually end TLS at that load balancer.
  • Databases are accessories pinned to a host, which "are not updated when you deploy, and they do not have zero-downtime deployments" (accessories).
  • No private network across servers, so the WireGuard advice above applies.

Where it wins: I think it's the best pick if you're on Rails and like config files. Where it falls short: no Compose files, a registry to run, and a load balancer to add.

K3s and Nomad: real orchestrators

Both are more machinery than most small apps need, and neither reads Compose files.

K3s is Kubernetes in one binary. Server nodes need 2 cores and 2 GB of RAM, agents 1 core and 512 MB (K3s requirements). Nodes talk on 6443/tcp for the API, 8472/udp for Flannel VXLAN and 10250/tcp, or 51820/udp with Flannel's WireGuard backend. You get everything Kubernetes has, and everything it asks of you: manifests or Helm charts, and a control plane to keep healthy. High availability with embedded etcd means three server nodes.

Nomad is simpler than Kubernetes. HashiCorp says "usually running 3-5 servers in a region is recommended", sized at "4-8+ cores, 16-32 GB+ of memory" (Nomad requirements). You can run smaller, but that tells you who it's built for. For DNS-style discovery and health-filtered routing, the docs point to Consul (service discovery), which is one more system to run.

Where they win: you already know them, or you're heading to dozens of servers. Where they fall short: for two or three servers running a few apps, they're the kind of thing I built Ployz to avoid.

Ployz: servers on one private network, no orchestrator to run

Ployz joins servers into one encrypted WireGuard network and deploys services onto them, without Kubernetes, Swarm or Compose. Adding a server is one command, pasted from the dashboard:

curl -fsSL https://ployz.sh/ | sh && sudo ployz server add --token …
  • Private network: Postgres doesn't need a public port. Services reach each other at NAME.internal, like Compose's db, but across servers.

  • Replicas: up to 50 per service, spread one per server first.

  • Load balancing: every server runs its own Caddy and serves HTTPS, so there's no load balancer to rent.

  • Deploys: push to GitHub and it builds on your servers, with no registry. With a health check set, the new version must pass it before the old one stops.

  • Ports: TCP 80, TCP and UDP 443, and UDP 51820 between servers.

  • Databases: a volume lives on one server, with a restore point. Move the database to another server with seconds of downtime.

  • Monitoring: metrics and searchable logs for every service and server, in the same dashboard.

Your Compose file: Ployz doesn't import it, so you set up each service from an image, a Dockerfile or a GitHub repo. A 15-service Compose file you want to run as-is fits Swarm better, or Coolify and Dokploy if one or two servers is enough (best self-hosted PaaS, Coolify vs Ployz).

How do you load balance containers across servers?

Something has to receive traffic and forward it to healthy containers on each server. Swarm's routing mesh and K3s's ingress do it inside the cluster. With contexts, WireGuard or Kamal, you add it yourself.

ShapeCostWeak point
Rented load balancer (e.g. Hetzner LB11)€6.99/month in Germany (Hetzner)One more bill per project; tied to one provider's network
Caddy or nginx on one of your serversFreeThat server is now a single point of failure
DNS with several A recordsFreeVisitors can still be sent to a dead server until you change DNS
Caddy on every server (Ployz)No extra costRoot domains on A records need a dead server's IP removed by hand

In Ployz, any server can take traffic and route it to a replica on another server over the private network. Generated addresses and custom domains on a CNAME stop sending visitors to a dead server within the hour.

What happens to databases and volumes?

They stay on one server. A Docker volume lives on the disk of the machine that created it. Swarm and Kamal leave volumes where they are, and moving one means stopping the database, copying the data and starting it elsewhere. Ployz moves a database to another server with seconds of downtime. Kubernetes with networked storage is the other exception, and it's its own project.

The pattern I'd use: app replicas on two or more servers, the database on one, a private network between them, and backups of the database on another machine. If your database is the reason you're scaling, Railway Postgres covers what a busy database costs on a platform. That's the bill that pushed me off Railway: $500+ a month, before I moved everything to one €80 dedicated server.

Which option should you pick?

If you need…Pick
The same Compose stack on independent serversDocker contexts
One app across servers with tools you knowWireGuard + Compose per server
Replicas and a cross-host network from DockerDocker Swarm
A config file, Rails-styleKamal
Dozens of servers, or you already run themK3s or Nomad
A private network, service names across servers and no load balancer to rent, from a dashboardPloyz

If you're weighing this against a hosted platform, PaaS pricing and Railway alternatives show what the same apps cost there.

Where Ployz fits

I built Ployz because I wanted more than one server without Kubernetes, a control plane or a three-server minimum. You add a server with one command. Servers share one encrypted network, and services find each other by name. Every server serves https, so there's no load balancer to rent.

ployz up --server root@your-server

Paste one line into Claude Code, Codex or Cursor and it adds your server and deploys. Every deploy, restart or delete your agent asks for waits for you to approve. When a server gets small, you move the database to a bigger one.

Ployz is free on any number of servers. Get started.

FAQ

Can Docker Compose deploy to a remote server?

Yes. Set DOCKER_HOST or use a Docker context with an SSH address, and normal docker compose commands run against that server. It's still a single-host deployment on that server.

Does docker stack deploy accept any Compose file?

No. It uses the legacy Compose v3 format, ignores build, and needs images in a registry every node can pull from.

Is Docker Swarm deprecated?

No. Swarm mode is part of Docker Engine, and Mirantis has committed to supporting it through at least 2030. "Classic Swarm", the older standalone product, is the one that's no longer developed.

Do I need Kubernetes to run containers on two servers?

No. Docker contexts, WireGuard with Compose, Kamal, Swarm and Ployz all run containers across servers without Kubernetes. You need Kubernetes-level tooling only if you want its scheduling and networked storage.

Can two Compose stacks on different servers share a network?

Not by themselves. Compose networks are bridge networks on one machine. Put the servers on WireGuard or Tailscale and bind ports to private addresses, or use Swarm's overlay network.

How I checked

I checked every fact on 2026-10-01 against Docker's, Kamal's, HashiCorp's, K3s's, Tailscale's and Hetzner's own docs and pricing pages, linked next to each claim. I haven't benchmarked these setups for this article; where I give an opinion, I say so.

Run your app across your own servers with Ployz: get started.

Run your apps and databases on your own servers with Ployz.

Deploy your app