Making Dokploy Survive Losing Its Main Node
On this page
Dokploy builds applications from a Git repository, deploys them to a Docker Swarm cluster, and sets up their routes and certificates in Traefik. You can add more servers to the cluster, but by default all public traffic still enters through one machine.
In my cluster that machine ran the Dokploy UI, its Postgres and Redis databases, and the only Traefik instance. A placement constraint kept Traefik on that node, where it published ports 80 and 443 in host mode, and every public domain resolved to the node’s address. The cluster had three healthy managers, but if that node failed, every site would have gone down.
The Dokploy project knows about this. Issue #920 asked for replicated Traefik and was closed after Dokploy stopped overwriting Traefik’s environment, ports and volumes, so you can now configure replication yourself. Issue #2939 is still open. A reply in discussion #4493 points out that open-source Traefik isn’t cluster aware, so each instance works independently and adding replicas isn’t enough.
What this setup covers
I wanted public traffic to keep flowing when any one node fails. That takes a load balancer and a Traefik instance on more than one manager.
This setup leaves the Dokploy control plane as it was. The UI, Postgres and Redis are still single instances, and making them highly available is a much larger project. If they go down, deployments stop and running containers keep serving traffic. I accepted that risk and wrote the decision down.
Enable PROXY protocol in Traefik
I already had a cloud load balancer that health-checked all three managers, but it carried no traffic because DNS still pointed at the main node. Requests through the load balancer returned 400 Bad Request with Connection: close and no Traefik headers. Requests sent straight to a node returned 200.
You can reproduce the difference from the command line:
# direct to the node
curl -sI -H 'Host: example.internal' http://NODE_IP/
# HTTP/1.1 200 OK
# same request, with a PROXY protocol v1 preamble prepended
printf 'PROXY TCP4 203.0.113.9 10.0.0.12 43210 80\r\nGET / HTTP/1.1\r\nHost: example.internal\r\n\r\n' \
| nc NODE_IP 80
# HTTP/1.1 400 Bad Request
The load balancer was sending PROXY protocol and Traefik wasn’t configured to accept it, so Traefik read the PROXY TCP4 ... line as a malformed HTTP request. On port 443 the same line broke the TLS handshake and produced a protocol-version alert.
Enable PROXY protocol on both entry points in Traefik’s static configuration:
entryPoints:
web:
address: ':80'
proxyProtocol:
trustedIPs:
- 10.0.0.2/32 # the load balancer's private address
websecure:
address: ':443'
proxyProtocol:
trustedIPs:
- 10.0.0.2/32
Turning PROXY protocol off at the load balancer also stops the 400, but Traefik then sees the load balancer’s address as the client address on every request. Rate limiting and access logs would no longer identify real clients.
To find the address to trust, watch the health checks arrive:
tcpdump -nni eth0 'tcp port 80 and tcp[13] & 2 != 0'
Traefik uses the PROXY header when the connection comes from a trusted address and ignores the header from other addresses. Requests sent directly to a node still work, so you can move DNS to the load balancer whenever you are ready.
Certificates with several Traefik instances
Open-source Traefik stores certificates in acme.json, a plain file with no locking. If three instances write to one copy on shared storage, they can corrupt it and you can lose every certificate in it.
The HTTP-01 challenge also fails with several instances, because only the instance that started a challenge has the token that answers it. Let’s Encrypt validates from several network locations and most of them must succeed. Behind a round-robin load balancer, most of those requests reach an instance that doesn’t have the token. You can route /.well-known/acme-challenge to one instance, but that instance becomes a special case you have to maintain. I used DNS-01.
Dokploy keeps Traefik’s configuration under /etc/dokploy/traefik, and you can share that directory over NFS. Keep acme.json off the shared directory.
Store certificates on each node
Mount a local directory from each node at the same path in every container, and point ACME at it:
certificatesResolvers:
letsencrypt:
acme:
storage: /acme/acme.json
docker service update \
--mount-add type=bind,source=/var/lib/traefik-acme,target=/acme \
dokploy-traefik
Copy the existing acme.json to each node before the new replicas start. Without it, the new instances start empty, request certificates for every hostname you serve, and can reach Let’s Encrypt’s rate limit.
After that, each replica renews its own certificates, so Let’s Encrypt receives three requests for every hostname. Three replicas stay well inside its limits, but ten would not.
Use the DNS-01 challenge
With DNS-01, Let’s Encrypt validates a DNS record, so it doesn’t matter which Traefik instance receives a request.
Dokploy writes one configuration file per application, and each file names a certResolver. Dokploy rewrites those files on the next deploy, so change the resolver they all refer to:
certificatesResolvers:
letsencrypt:
acme:
storage: /acme/acme.json
dnsChallenge:
provider: cloudflare
propagation:
delayBeforeChecks: 30s
The application files still ask for letsencrypt and keep working. Existing certificates stay valid, because Traefik uses the challenge only when it issues or renews a certificate. Traefik v2 uses delayBeforeCheck: 30, which v3 deprecated in favour of the propagation block.
You can store the DNS credential in a swarm secret, because Traefik’s ACME library, lego, accepts a _FILE version of many credential variables and reads the token from that file:
printf '%s' 'TOKEN' | docker secret create dns_api_token -
docker service update \
--secret-add source=dns_api_token,target=dns_api_token \
--env-add CLOUDFLARE_DNS_API_TOKEN_FILE=/run/secrets/dns_api_token \
dokploy-traefik
Swarm encrypts the secret at rest, keeps its value out of docker service inspect, and delivers it to every node that runs the service.
To test DNS-01, add a temporary router for a hostname that has no A record:
http:
routers:
dns01-check:
rule: Host(`dns01-check.example.com`)
service: noop
entryPoints: [websecure]
tls:
certResolver: letsencrypt
The service can be a placeholder because it never receives a request. If Traefik gets a certificate for that name, Let’s Encrypt must have validated it through DNS. Remove the router afterwards.
Domains in another DNS account
Traefik reads one set of credentials per DNS provider for the whole process, so a second resolver can’t use a different account with the same provider. For a domain in an account you can’t write to, ask its owner to add a CNAME that points the challenge record at a zone you control:
_acme-challenge.app.client-domain.test CNAME app.acme.your-domain.test
Traefik writes the TXT record in your zone, and Let’s Encrypt follows the CNAME to it. Neither account shares a credential with the other. lego follows the CNAME by default unless you set LEGO_DISABLE_CNAME_SUPPORT=true.
Origin certificates for domains behind a CDN
If a hostname always sits behind a CDN that terminates TLS, you can use an origin certificate from the CDN provider. Cloudflare’s are free, valid for years, and stored as files that every replica can read, so there is nothing to lock or renew often.
Cloudflare’s Origin CA issues the certificate used between Cloudflare and your server, and it is free on every plan. Advanced Certificate Manager is a paid product for the certificates used between visitors and Cloudflare, and you don’t need it for this.
Run Traefik on every manager
docker service update has no --mode flag, so changing Dokploy’s Traefik service from replicated to global means deleting and recreating it, which takes every site offline. You can get the same placement by updating the replicated service:
docker service update \
--constraint-rm 'node.hostname==primary' \
--constraint-add 'node.role==manager' \
--replicas 3 \
--replicas-max-per-node 1 \
dokploy-traefik
Keep the manager constraint when you remove the hostname one. Without it, on a cluster with five workers, Swarm can place all three replicas on nodes that the load balancer doesn’t target. Traefik’s Swarm provider also needs to reach a manager’s API.
Host-mode ports already prevent two replicas from running on one node. --replicas-max-per-node 1 makes that rule explicit.
Convert Docker Compose apps to stacks
Some of my Docker Compose apps broke when Traefik moved to three nodes, and I only noticed weeks later. The symptom looked like a certificate problem.
Traefik’s providers.docker reads only the local Docker daemon. Dokploy applications run as swarm services, and Traefik’s Swarm provider sees those across the cluster. A Dokploy compose of type docker-compose runs as plain containers on one node. The Traefik instance on that node creates a route and gets a certificate, and the other two instances never learn that the hostname exists.
With three instances behind the load balancer, about two in three requests reach an instance without the route. TLS fails there with CN=TRAEFIK DEFAULT CERT.
On the node that runs the container, the container is healthy, Dokploy reports success, the certificate is valid, and curl returns 200. A short test can also mislead you. When I sent five requests through the load balancer, all five succeeded. When I sent thirty in sequence, only four did.
Ask each Traefik instance whether it has the route:
for h in mgr1 mgr2 mgr3; do
ssh root@$h 'C=$(docker ps -q -f name=dokploy-traefik | head -1)
docker exec $C sh -c "wget -qO- http://127.0.0.1:8080/api/http/routers" \
| tr "," "\n" | grep -c "your-host"'
done
Every instance must report a count above zero.
To fix an affected app, set its composeType to stack so that Dokploy deploys it as a swarm service. In swarm mode Traefik reads labels from the service, so routing labels belong under deploy.labels. Dokploy puts them there, and you can confirm it with docker service inspect.
If the stack uses host-path volumes, pin it to the node that holds the data:
deploy:
placement:
constraints:
- node.hostname==the-node-holding-the-data
Without the constraint, Swarm may start the container on a node where those paths are empty, and some applications then create a new, empty database without reporting an error.
The conversion fails if the old network still exists, because docker compose created a local bridge network and docker stack deploy needs an overlay network with the same name:
failed to create network app_default: network with name app_default already exists
Remove the old container and network before you deploy the stack. This is safe when the volumes are host paths, because the data is outside the container.
Certificate conflicts on new hostnames
Because each instance has its own certificate store, each one requests its own certificate for a new hostname. With DNS-01, all three write and delete the same _acme-challenge record at the same time:
403 orderNotReady :: Order's status ("processing") is not acceptable for finalization
400 malformed :: Unable to update challenge :: authorization must be pending
When you add one hostname, usually one instance fails and doesn’t retry for several minutes. When you add two at once, all six requests can fail, and no instance has a certificate for either name.
Restarting every instance together causes the same conflict, so restart them one at a time, and wait until each instance has its certificate before you restart the next:
ssh root@node1 'docker restart $(docker ps -q -f name=dokploy-traefik | head -1)'
# wait until this node stops serving TRAEFIK DEFAULT CERT, then move to node 2
An origin certificate avoids the conflict because every instance reads the same file. Only the CDN trusts that certificate, so if someone later turns off the CDN proxy for that DNS record, visitors get a TLS error immediately.
If you add hostnames often, run lego or certbot on a schedule as the only issuer and write the certificates to the shared configuration directory. Each certificate is then issued once and trusted by browsers.
Settings to maintain outside Dokploy
This setup depends on six settings, and Dokploy’s database has no field for any of them:
proxyProtocolon both entry points- ACME storage on each node’s local disk
dnsChallengein the resolver definition- the DNS credential in the service environment
- the secret mount that holds the credential
- the placement rules that put one replica on each manager
Dokploy no longer overwrites Traefik’s environment, ports and volumes when its own container restarts, so the DNS credential setting survives a restart. That change doesn’t cover placement, secrets or the configuration file, and running the install script again is a separate risk. I treat all six as mine to maintain.
Some of these fail visibly when they are lost. Requests through the load balancer return 400, or the load balancer marks two nodes as unhealthy. If the DNS credential is lost, sites keep working until a certificate needs renewal, around day 60 of 90. Renewal then fails, and visitors see nothing until the certificate expires 30 days later.
Write a script that re-applies all six and is safe to run repeatedly. Check for drift every few hours, so that you learn about a lost credential long before a certificate expires.
Two mistakes in my drift check
Two of my checks gave wrong results, and I only found out when I tested the checks themselves.
The first check counted DNS credential errors in the last six hours of logs. It failed on a healthy cluster because it counted errors from before the fix. It now reads only the logs since the service was last updated:
SINCE=$(docker service inspect dokploy-traefik --format '{{.UpdatedAt}}' \
| awk '{gsub(/\..*/,"",$2); print $1"T"$2"Z"}')
docker service logs --since "$SINCE" dokploy-traefik 2>&1 \
| grep -ic 'credentials information are missing'
The second check sent a request to the load balancer and expected 200, to confirm that PROXY protocol was configured. Traefik listens on 0.0.0.0 on every manager. When the check resolved to an address that the node answered itself, the request never reached the load balancer, so it passed with or without PROXY protocol. I confirmed this by removing proxyProtocol and running the check, which still passed.
That check now reads the configuration, and I kept the request only as a test that Traefik is responding.
What this setup doesn’t protect
Traffic now survives the loss of any one node. Deployments still depend on the main node, because the Dokploy control plane runs only there.
The cluster and its load balancer are in one availability zone, so a datacentre failure would still take everything down. Traefik’s configuration is on one NFS export outside the cluster, and a Traefik instance that restarts while that server is unavailable can’t load its routes.