High Availability
Keep a stateless application responding when one of its containers or a worker node goes down.
High availability runs your application as at least 2 replicas spread across the nodes of your Docker Swarm cluster. If a container crashes or a worker node goes down, the other replicas keep serving traffic while Swarm starts a replacement on a healthy node.
It's available for applications deployed on a cluster with 2 or more nodes. You turn it on from the Advanced tab of the application.
What it protects against
| Failure | Result |
|---|---|
| A container crashes or stops responding | Swarm removes it from traffic and starts a new one. The other replicas keep responding. |
| A worker node goes down | The replicas on that node are started again on the other nodes. The other replicas keep responding while that happens. |
| A deploy with a broken image or a failing health check | Swarm rolls back to the previous version on its own and the deployment is marked as failed. |
| The manager node goes down | Not covered. Traefik runs on the manager, so traffic stops until the manager is back. |
High availability covers the application only. If the application depends on a database that runs on a single node and that node goes down, the application keeps responding but its requests to the database fail.
How traffic reaches the replicas
Your domain points to the manager node, where Traefik runs. Traefik receives every request, handles TLS, and forwards the request over the swarm network to one of the replicas, on any node.
user ──HTTPS──> manager (Traefik) ──> replica on node 2
└──> replica on node 3This means:
- The work of the application (CPU, memory, database queries) is spread across the nodes that run replicas.
- Every connection, TLS handshake and byte of the responses goes through the manager. Applications that serve large files or a lot of bandwidth need a manager with enough network capacity.
Swarm balances per connection, not per request. Traefik keeps connections to the application open and reuses them, so a client sending one request after another can be served by the same replica. Under concurrent traffic, requests are spread across the replicas.
Requirements
Dokploy checks every requirement before it lets you enable high availability. All of them must pass.
- No volumes or file mounts. Mounts live on the disk of a single node, so a replica on another node would start with empty data. Store files in a database or object storage (S3) instead.
- The image can be pulled by every node. Applications deployed from a Docker image already meet this. Applications built by Dokploy (Git, Dockerfile, Nixpacks, etc.) need a registry selected in Cluster Settings, so the image is pushed and the other nodes can pull it. See Cluster to configure one.
- At least 2 nodes available. Nodes must be
ReadyandActive. With Run replicas only on worker nodes enabled, you need at least 2 worker nodes. - A health check. Without a health check, Swarm sends traffic to a new container as soon as it starts, before the application is ready, and it can't detect a broken deploy to roll it back.
- No ports in host mode. A port published in host mode can only be used by one replica per node. Use ingress mode, or route the application through a domain.
Add a health check
Go to Advanced → Cluster Settings → Swarm Settings → Health Check and set a command that succeeds only when the application is ready to serve requests. For example, for an application listening on port 3000 with a /health route:
{
"Test": ["CMD-SHELL", "curl -f http://localhost:3000/health || exit 1"],
"Interval": 10000000000,
"Timeout": 5000000000,
"StartPeriod": 10000000000,
"Retries": 3
}The command runs inside the container, so the tool it uses (curl, wget, etc.) must exist in the image. Times are in nanoseconds: 10000000000 is 10 seconds.
Enable high availability
- Open the application and go to the Advanced tab.
- In the High Availability card, check that every requirement shows a green check. Fix the ones in red.
- Optional: turn on Run replicas only on worker nodes (see below).
- Click Enable.
- Click Deploy to apply the changes.
When you enable it, Dokploy sets these Swarm settings for the application:
- Replicas: at least 2.
- Placement: a spread preference on
node.id, so replicas go to different nodes. With Run replicas only on worker nodes, also the constraintnode.role==worker. - Update Config and Rollback Config: one replica at a time (
Parallelism: 1), stopping the old container before starting the new one (Order: stop-first), and rolling back when the update fails (FailureAction: rollback).
With 2 or more replicas, updating one replica at a time with stop-first keeps the application responding: the other replicas serve traffic while one is replaced. The start-first order isn't used because it makes Swarm place the new replica next to the old ones, so the replicas can end up on the same node.
To turn it off, click Disable and deploy again. The application goes back to 1 replica and the spread preference and worker constraint are removed.
Run replicas only on worker nodes
All traffic enters through Traefik on the manager. If replicas also run on the manager, the application competes with Traefik for CPU and network, and a busy application can slow down routing for every other application.
With Run replicas only on worker nodes enabled, replicas run only on worker nodes and the manager only routes traffic. This requires at least 2 worker nodes. If a worker goes down, its replicas move to the other workers, never to the manager.
We also recommend using a build server, so builds don't use the CPU of the node that routes traffic.
Replica status
When high availability is enabled, the card shows how many replicas are running and on which node each one runs. It refreshes every 10 seconds.
The status is Degraded when:
- Fewer replicas are running than configured. For example, while Swarm replaces a replica that stopped or starts the replicas of a node that went down.
- The replicas are stacked on fewer nodes than available. This usually happens after a node goes down and comes back: Swarm moves its replicas to the other nodes, but doesn't move them back when the node returns.
- All replicas run on a single node because it's the only one available. The application keeps responding, but if that node goes down, the application goes down too. Bring the other nodes back or add new ones.
Rebalance
When the replicas are stacked while other nodes are available, the card shows a Rebalance button. It forces Swarm to recreate the replicas one at a time (the same as docker service update --force), so they are spread across the nodes again.
Rebalance doesn't build or deploy a new version: it uses the same image and settings. Because replicas are replaced one at a time and only after the new one passes its health check, the application keeps responding during the rebalance.
Set up a domain
Nothing changes compared to a regular application. Create an A record that points the domain to the IP address of the manager node and add the domain in the Domains tab. Let's Encrypt certificates work as usual.
What to expect when something fails
These are the results we measured on a cluster of 1 manager and 2 workers, with HTTPS traffic of 8 concurrent requests during each test:
| Test | Failed requests |
|---|---|
| Deploy with high availability enabled | 0 of 1800 |
| Docker stopped on a worker node | 0 of 1032 |
| Network of a worker node cut suddenly | 1 of 1160 (one request timed out at the moment of the cut) |
| Deploy of a broken image, with a health check | 0 of 1632, rolled back automatically and marked as failed |
| Rebalance of 2 replicas stacked on one node | 0 of 1806 |
A node that loses its network suddenly is detected by Swarm after a few seconds. Requests already sent to a replica on that node in that moment can fail.