dokploy icon indicating copy to clipboard operation
dokploy copied to clipboard

Traefik fails to start after ungraceful reboot (dynamic overlay network attachments from isolated deployments don't survive restore)

Open Code-Divine opened this issue 8 months ago • 6 comments

To Reproduce

Deploy Dokploy on a single-node Docker Swarm setup Ensure Traefik is running and Dokploy is accessible via domain Resize Azure VM (or otherwise trigger a full VM reboot) After reboot: Docker and Dokploy containers start dokploy-traefik fails to start

Attempt to manually start Traefik:

docker start dokploy-traefik

→ fails with networking error

Current vs. Expected behavior

Current behavior:

Dokploy container is running and healthy (Server Started on: http://0.0.0.0:3000) dokploy-traefik is stopped (Exited 128) Ports 80/443 are not exposed Dokploy UI is inaccessible

Starting Traefik fails with:

failed to set up container networking: attaching to network failed Overlay network shows IP conflict (Traefik IP already assigned to another container)

Expected behavior:

Traefik should automatically restart and reattach to dokploy-network No IP conflicts should occur after reboot Dokploy should remain accessible without manual intervention

Provide environment information

Dokploy version: v0.28.8
Docker version: 28.x
Deployment type: Single-node Docker Swarm
Cloud provider: Azure VM
Trigger: VM resize (causes reboot)
Network: Docker overlay network (dokploy-network)

Which area(s) are affected? (Select all that apply)

Traefik

Are you deploying the applications where Dokploy is installed or on a remote server?

Same server where Dokploy is installed

Additional context

No response

Will you send a PR to fix it?

No

Code-Divine avatar Mar 24 '26 01:03 Code-Divine

This is a known issue with Docker Swarm overlay network initialization and stale endpoint registrations after reboots. There are related reports in #1802 and #3236.

Workaround (from maintainer @Siumauricio):

# Remove the old container
docker rm -f dokploy-traefik

# Start WITHOUT the --network flag
docker run -d \
    --name dokploy-traefik \
    --restart always \
    -v /etc/dokploy/traefik/traefik.yml:/etc/traefik/traefik.yml \
    -v /etc/dokploy/traefik/dynamic:/etc/dokploy/traefik/dynamic \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -p 80:80/tcp \
    -p 443:443/tcp \
    -p 443:443/udp \
    traefik:v3.1.2

# Connect to network separately
docker network connect dokploy-network dokploy-traefik

After applying this fix, redeploy all services once via the Dokploy UI to re-register their routes with the new Traefik instance.

The root cause is a race condition where standalone containers try to attach to the overlay network before Swarm initialization completes. The two-step approach (create container first, then connect to network) works around this.

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about dokploy Share Dosu with your team

dosubot[bot] avatar Mar 24 '26 01:03 dosubot[bot]

This is a known issue with Docker Swarm overlay network initialization and stale endpoint registrations after reboots. There are related reports in #1802 and #3236.

Workaround (from maintainer @Siumauricio):

Remove the old container

docker rm -f dokploy-traefik

Start WITHOUT the --network flag

docker run -d
--name dokploy-traefik
--restart always
-v /etc/dokploy/traefik/traefik.yml:/etc/traefik/traefik.yml
-v /etc/dokploy/traefik/dynamic:/etc/dokploy/traefik/dynamic
-v /var/run/docker.sock:/var/run/docker.sock
-p 80:80/tcp
-p 443:443/tcp
-p 443:443/udp
traefik:v3.1.2

Connect to network separately

docker network connect dokploy-network dokploy-traefik After applying this fix, redeploy all services once via the Dokploy UI to re-register their routes with the new Traefik instance.

The root cause is a race condition where standalone containers try to attach to the overlay network before Swarm initialization completes. The two-step approach (create container first, then connect to network) works around this.

To reply, just mention @dosu.

How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

This is a deal-breaking issue for us. If anything causes the server to crash, after reboot I will have to manually intervene. It should be fixed

Code-Divine avatar Mar 25 '26 21:03 Code-Divine

Standard containers cannot reliably start after a reboot if they are attached to swarm overlay networks. Overlay networks only become available after swarm initializes, so standalone containers hit a race condition on boot. Swarm and plain docker also manage container lifecycles differently swarm creates new tasks, docker restarts existing containers, which can lead to conflicting network endpoints and stale ip assignments.

There are three realistic ways to solve this:

  1. Run traefik as a swarm service This guarantees the overlay network exists before traefik starts. However, you lose the real client ip unless you use something like cf tunnel. host mode is not practical as you don't see any containers

  2. Use a double proxy Run one proxy outside swarm on a normal bridge or host network. Run a second proxy inside swarm that listens on a different published port. The outer proxy terminates TLS and preserves client IPs, then forwards to the internal proxy if no matches (not all services usually run inside swarm). This avoids overlay network race conditions entirely. (But it only solves the traefik problem other standalone containers would still need handling by moving off the overlay networks.)

  3. Implement a recovery mechanism in dokploy On boot, dokploy could detect failed standalone containers attached to overlays, remove them, and recreate them after swarm is ready. This seems impractical.

Ultimately I think dokploy’s orchestration model has a flaw:
Standalone containers should never be attached to swarm overlay networks without a guaranteed recovery, a delayed attach doesn't work since docker will restart the old container, but that ip might be assigned to a new swarm task as shown above. Swarm services and standalone containers operate under different assumptions, and mixing them on overlay networks will usually create race conditions after a reboot.

djsisson avatar Mar 27 '26 20:03 djsisson

After a simple server reboot, dokploy-traefik tried to use an IP that was already assigned to another container in dokploy-network.

This caused:

failed to set up container networking: attaching to network failed could not allocate IP from IPAM: Address already in use

As a result, Traefik did not start, ports 80/443 stopped listening, and all Dokploy apps became unreachable even though the app containers were running.

This is critical. A reboot should not be able to break the reverse proxy for every deployed app. Dokploy should detect and automatically repair stale/duplicate overlay network IP conflicts.

jjjjose avatar Jun 05 '26 21:06 jjjjose

I had to disable auto update on my VM to prevent Dokploy from randomly breaking because of this issue. It causes a domino effects on my node, some services are shown as running meanwhile their container does not exist.

steadexe avatar Aug 06 '26 08:08 steadexe

Update — root cause found and reproduced.

We managed to reproduce this deterministically, and it is not a Docker version problem (it reproduces the same on Docker 28.x and 29.x). It is a design issue on our side, and it is fragile by nature:

  • A standalone container attached to multiple swarm overlay networks via docker network connect fails to restore after an ungraceful reboot (VM resize, power loss, daemon crash). The daemon restores containers before the swarm-scoped networks are available, the start fails with failed to set up container networking: ... network not found / attaching to network failed, and --restart always does not retry that failure, so Traefik stays down (Exited (128)).
  • This is exactly the state Dokploy creates when you use isolated deployments: each isolated compose runs docker network connect <compose-network> dokploy-traefik, so Traefik accumulates dynamic attachments.
  • With the network defined at container creation instead, the container survives ungraceful restarts reliably (we killed the daemon repeatedly in testing and it recovered every time), and a Traefik attached only to dokploy-network at create time survives full VM reboots.

Two consequences:

1. Updated recovery command. The workaround posted earlier in this thread (create without --network, then docker network connect) brings Traefik back, but it recreates the fragile state — the dynamic attachment can die again on the next reboot. Use this instead (note --network dokploy-network is now part of the docker run itself):

docker rm -f dokploy-traefik

docker run -d \
    --name dokploy-traefik \
    --restart always \
    --network dokploy-network \
    -v /etc/dokploy/traefik/traefik.yml:/etc/traefik/traefik.yml \
    -v /etc/dokploy/traefik/dynamic:/etc/dokploy/traefik/dynamic \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -p 80:80/tcp \
    -p 443:443/tcp \
    -p 443:443/udp \
    traefik:v3.6.7 # use the same tag as your existing Traefik container

If a stuck container refuses to start right after boot, a plain docker start dokploy-traefik once the swarm is up also works — the state is not corrupted, the start just raced the swarm network initialization.

2. The plan. The dynamic network connect pattern exists only to support isolated deployments. Now that proper network management has landed (per-service networks, network CRUD), we are going to deprecate that mechanism in the next version: Traefik will keep a single network attachment defined at creation time, and service isolation will be handled through user-defined networks instead.

Siumauricio avatar Aug 09 '26 06:08 Siumauricio