Skip to content

Wait for in-progress container removal before starting Compose services - #1359

Draft
Christof Marti (chrmarti) wants to merge 2 commits into
mainfrom
chrmarti/compose-removing-container
Draft

Christof Marti (chrmarti) wants to merge 2 commits into
mainfrom
chrmarti/compose-removing-container

Conversation

@chrmarti

Copy link
Copy Markdown
Contributor

A Rebuild can leave the previous Docker Compose container in the removing state while devcontainer up runs (for example, when the old window's shutdown monitor is still removing it). findComposeContainer returns that container and up -d --no-recreate then fails with "container is marked for removal and cannot be started". Single-container configs already skip removing containers in findDevContainer, but Compose has to wait because the old container keeps the <project>-<service>-1 name until it is gone.

Changes:

  • Compose: when the service container is in the removing state, wait for its removal to finish ("Waiting for existing container to be removed.") and create a new container.
  • removeContainer: while Docker reports "removal of container ... is already in progress", keep waiting for up to 5 minutes instead of giving up after 7 attempts (about 7 s). Removing large containers can take longer (19 s in the report).

Validation:

  • New unit test with a fake exec: 8 "already in progress" conflicts, then success. It fails without the change.
  • Existing "protects against concurrent removal" test against real Docker.
  • Manual end-to-end repro on Docker Desktop: docker rm -f on a Compose dev container with 2M files, then devcontainer up. Without the change, up fails at docker compose up (removal took about 46 s). With the change, it waits about 38 s and creates a new container.

Fixes microsoft/vscode-remote-release#11967

A Rebuild can leave the previous Compose container in the 'removing' state while 'up' runs. Starting it with 'up --no-recreate' then fails with 'container is marked for removal and cannot be started'. Wait for the removal to finish and create a new container instead.

removeContainer also gave up after 7 attempts (about 7 seconds) while a removal was in progress. Wait up to 5 minutes instead, since removing large containers can take longer.

Fixes microsoft/vscode-remote-release#11967

Co-authored-by: Copilot <[email protected]>
@chrmarti
Christof Marti (chrmarti) requested a balanced review from Copilot November 16, 2026 20:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A container in the removing state can be automatically replaced despite --expect-existing-container, silently creating a new environment when the caller requires an existing one.

1 open issue
What changed in this PR

Updates Compose dev-container startup to wait for an old container’s removal before creating its replacement, addressing rebuild failures caused by containers still marked removing.

Changes:

  • Detects removing Compose containers and waits before replacement.
  • Extends retries for in-progress removal from seven attempts to a five-minute window.
  • Adds a regression test covering eight removal conflicts followed by success.
File Description
src/​test/​dockerUtils.test.ts Tests removal retries beyond the previous seven-attempt limit.
src/​spec-shutdown/​dockerUtils.ts Adds a five-minute retry window and a one-time waiting message.
src/​spec-node/​dockerCompose.ts Routes containers marked removing through removal before startup.

Review effort: Balanced

Comment thread src/spec-node/dockerCompose.ts Resolved
With --expect-existing-container, a Compose container in the removing state passed the existence check and was then replaced by a new one. Reject it like the single-container path does. Also test that waiting for an in-progress removal stops after five minutes.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the Compose container-removal handling changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rebuild Container (Docker Compose) still races the old container's removal: "container is marked for removal and cannot be started"

2 participants