dokploy icon indicating copy to clipboard operation
dokploy copied to clipboard

Dokploy doesn't clean instances after redploy

Open oussamaboumaad opened this issue 4 months ago • 4 comments

To Reproduce

1- create app 2- try to stop and deploy multiple times 3- you'll see in logs one or more apps are still running

Image

Current vs. Expected behavior

when redeploy or deploy, dokploy should kill all running apps and start one fresh (this was the behavior we used to see before)

Provide environment information

ubuntu 20.04 
dokploy : 0.29.13

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

Application

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

Same server where Dokploy is installed

Additional context

Image this app has one replica in the advanced setttings, when I deploy or reload, it basically create one new but doesn't kill the current running one.

Will you send a PR to fix it?

Maybe, need help

oussamaboumaad avatar Jul 24 '26 14:07 oussamaboumaad

This looks like a known limitation with how Docker Swarm handles service updates, and there are a few likely causes depending on your setup:

1. Host port publishing mode — If your app uses Host port mode (rather than Ingress), Docker Swarm cannot update the service in-place, so the old task keeps running alongside the new one [1]. This has been confirmed by maintainers as a Swarm limitation. Fix: Switch your port mode from Host to Ingress in the application settings, or use a Stop → Deploy workflow instead of just redeploying.

2. start-first update order — Dokploy defaults to Order: "start-first" for update config [2], which starts the new task before stopping the old one. If the new task fails to fully start or there are resource conflicts (e.g., volume locks), the old task can linger. This was already addressed for database services in PR #4560 by switching them to stop-first. You can try changing your app's Update Config order to stop-first in the Advanced settings.

3. No explicit old-task cleanup — The deploy path (mechanizeDockerContainer) only increments a ForceUpdate counter on service updates rather than using docker service update --force [3]. Neither the stop nor deploy paths explicitly remove old Swarm tasks — they rely on Swarm to handle cleanup [4].

Immediate workaround: Try a full Stop → Deploy cycle rather than just redeploying. Also check your port publishing mode in the app's Ports settings — if it's set to Host, switching to Ingress should resolve it.

If you want to contribute a fix, the key area is the mechanizeDockerContainer function — it could benefit from either using --force on service updates or explicitly cleaning up old tasks before creating/updating the service.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about dokploy with Dosu Add Dosu to your team

dosubot[bot] avatar Jul 24 '26 14:07 dosubot[bot]

I've figured out that by adding health checks to the Dockerfile we encounter this issue. as soon as I put a new version without health checks it fixes instantly.

magixus avatar Aug 04 '26 10:08 magixus

Triaged on v0.29.13 — I could not reproduce this.

What I tested (local Docker Swarm, application deployed as a Swarm service):

  1. Deployed an application and confirmed one running task.
  2. Ran two full Stop → Deploy cycles back to back through the API, waiting for status done each time.
  3. After the cycles: docker ps --filter name=<app> shows exactly one running container, and docker service ls reports 1/1 replicas.

Older exited containers stay listed in docker ps -a (that's normal Swarm task history — Docker keeps terminated task containers around, they hold no resources), but no second running instance appears.

From your screenshot it looks like you may be seeing task history rather than duplicated running apps. Could you share the output of these two commands right after a redeploy, so we can tell them apart?

docker service ls --filter name=<your-app-name>
docker service ps <your-app-name> --no-trunc

If Replicas shows something like 2/1, or docker service ps lists more than one task in Running state, that's a real duplication and we'll dig in. Marking as awaiting-feedback until then.

Siumauricio avatar Aug 04 '26 20:08 Siumauricio

Closed due to inactivty

Siumauricio avatar Aug 13 '26 08:08 Siumauricio