Skip to content

Stopping a service leaves the container of a docker run service running (Windows) #245

Closed

Description

@fen89

What happened

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)

  1. A per-service stop step that devstack runs when it stops an instance, with the instance's placeholders:

    [services.ocr-api]
    build = "docker build -t ocr-api:dev ocr/api"
    run   = "docker run --rm --name ocr-api{lane_suffix}-{port} -p {port}:8000 ocr-api:dev"
    stop  = "docker rm -f ocr-api{lane_suffix}-{port}"
  2. 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.

Environment

  • devstack 0.20.0
  • Windows 11, Docker Desktop

Activity

  1. 7schmiede commented on Oct 23, 2026

    @7schmiede
    Member

    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:

    [services.ocr-api]
    build = "docker build -t ocr-api:dev ocr/api"
    run   = "docker run --rm --init --name ocr-api{lane_suffix}-{port} -p {port}:8000 ocr-api:dev"
    stop  = "docker rm -f ocr-api{lane_suffix}-{port}"

    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.

  2. 7schmiede commented on Oct 23, 2026

    @7schmiede
    Member

    Fixed in 0.21.0 by #247: [services.<name>] stop ends what a service's run started outside its process tree, such as a docker run container (ADR-0059).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions