You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stopping a service leaves the container of a docker run service running (Windows) #245
A service whose run is docker run --rm ... leaves its container running whenever devstack stops the service. On Windows devstack ends the docker CLI process, the container lives in the Docker VM and never notices.
Minimal stack file:
version = 1
[stack]
name = "killtest"requires = "0.20.0"
[services.box]
kind = "tool"run = "docker run --rm --name kill-test alpine sleep 300"
Action
Container afterwards
devstack start box, then devstack stop box
still Up
devstack start box, then devstack down
still Up
docker run CLI killed by hand (Stop-Process -Force)
still Up (same thing)
Expected: stopping the service stops what it started.
Why it matters
The use case is a service developed in the repository whose runtime needs Linux tools (a Python API with OCR: tesseract, ghostscript, unpaper), so it cannot run natively on a Windows machine. As a Compose container it gets no watch, no candidate and no per-lane {port}. As a service it would get all of that with build = "docker build -t img ..." and run = "docker run --rm -p {port}:8000 img", but:
every rebuild leaves the previous instance's container running (memory, CPU);
a later start on the same internal port fails with port is already allocated, and devstack reports a failed start although the code is fine;
after devstack down the container keeps running until someone runs docker rm -f.
A docker rm -f before docker run in run is no way out: with a fixed name or label it also removes the main instance while the candidate is still starting.
Proposal (either would do)
A per-service stop step that devstack runs when it stops an instance, with the instance's placeholders:
Or a graceful stop on Windows before the hard one (CTRL_BREAK_EVENT to a process started in its own process group, then a timeout): docker run should then stop the container (--sig-proxy, the default; not verified for CTRL_BREAK), and other processes that clean up on Ctrl+C would benefit too.
Option 1 also covers processes that do not react to signals at all.
Thanks for the detailed report. I reproduced it with 0.20.0, and the cause is a different one than it looks like:
devstack already stops gracefully on Windows (option 2): it sends Ctrl+Break to the service's process group, and the docker CLI forwards it to the container as SIGINT. In the example, sleep runs as PID 1 in the container, and PID 1 ignores SIGINT unless it handles it. So devstack waits for the stop timeout (20 s), ends the CLI, and the container stays up. With docker run --rm --init … the same devstack stop takes 0 s and the container is gone; devstack down behaves the same. A server that handles SIGINT (uvicorn does) should stop cleanly too.
What remains is a process that does not react, and a crash of the daemon. #247 (ADR-0059) adds option 1 for that: a service's stop, run before the graceful signal with the instance's placeholders:
It runs whenever an instance ends: a stop, down, the old instance a candidate replaced, or one that ended on its own. After a daemon crash, the next start runs it. With {port} in the name, the candidate and the running instance do not remove each other.
Activity
7schmiede commentedon Oct 23, 2026
Thanks for the detailed report. I reproduced it with 0.20.0, and the cause is a different one than it looks like:
devstack already stops gracefully on Windows (option 2): it sends Ctrl+Break to the service's process group, and the
dockerCLI forwards it to the container as SIGINT. In the example,sleepruns as PID 1 in the container, and PID 1 ignores SIGINT unless it handles it. So devstack waits for the stop timeout (20 s), ends the CLI, and the container stays up. Withdocker run --rm --init …the samedevstack stoptakes 0 s and the container is gone;devstack downbehaves the same. A server that handles SIGINT (uvicorn does) should stop cleanly too.What remains is a process that does not react, and a crash of the daemon. #247 (ADR-0059) adds option 1 for that: a service's
stop, run before the graceful signal with the instance's placeholders:It runs whenever an instance ends: a stop,
down, the old instance a candidate replaced, or one that ended on its own. After a daemon crash, the next start runs it. With{port}in the name, the candidate and the running instance do not remove each other.docs(adr): ADR-0059 a service's stop command ends what its run starte…
feat: a service's stop command runs when devstack stops an instance (…
feat: a service's stop command runs when devstack stops an instance (…
7schmiede commentedon Oct 23, 2026
Fixed in 0.21.0 by #247:
[services.<name>] stopends what a service'srunstarted outside its process tree, such as adocker runcontainer (ADR-0059).