Skip to content

Conversation

@Pnkcaht
Copy link

@Pnkcaht Pnkcaht commented Jan 14, 2026

What I did

Adjusted the image pruning logic used by docker compose down to avoid removing images that are still in use by existing containers.

Before this change, Compose could attempt to remove images that were still referenced by running or stopped containers belonging to the same project, which resulted in unexpected behavior and errors during down --rmi.

The pruner now checks containers associated with the project and filters out images that are currently in use before scheduling them for removal.

Related issue

Fixes #13491

(not mandatory) A picture of a cute animal, if possible in relation to what you did

🐳 A whale carefully carrying containers instead of dropping them — just like Compose now avoids removing images that are still in use.

Notes

  • Only affects docker compose down with image removal enabled
  • Prevents removal of images still referenced by project containers
  • Existing behavior preserved for unused images
  • Covered and validated by unit tests (TestDownRemoveImages, TestDownRemoveImages_NoLabel)

Signed-off-by: pnkcaht <samzoovsk19@gmail.com>
Signed-off-by: pnkcaht <samzoovsk19@gmail.com>
@Pnkcaht Pnkcaht force-pushed the fix-compose-down-image-ownership branch from f1063f6 to 5a669d2 Compare January 14, 2026 23:52
Copy link
Contributor

@ndeloof ndeloof left a comment

Choose a reason for hiding this comment

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

engine detects image are in use by another container, simpler (imho) to let it manage this check (which will then not suffer from potential race conditions) and manage error during image removal attempts

)

// ImagePruneMode controls how aggressively images associated with the project
// are removed from the engine.
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you remove all comments?

Copy link
Member

Choose a reason for hiding this comment

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

I suspect it was written with AI, which has a tendency on doing so; I see various other changes (and comments added) that match that idea as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

obviously :)

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.

Service-scoped image removal in docker compose down

3 participants