Fix docker compose down removing images still in use #13515
+73
−91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I did
Adjusted the image pruning logic used by
docker compose downto 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
docker compose downwith image removal enabledTestDownRemoveImages,TestDownRemoveImages_NoLabel)