Repository navigation
fix(down): preserve images outside selected services - #14458
Merged
Merged
Conversation
Scope image pruning to selected services and their dependents. Keep images of declared but unselected services when removing orphans. Fixes docker#14453 Signed-off-by: Seyed Noorollah Aghayenoor <noorollah.aghayenoor@gmail.com>
ndeloof
previously approved these changes
Nov 5, 2026
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
glours
requested changes
Nov 5, 2026
glours
left a comment
Contributor
There was a problem hiding this comment.
Changes requested, all small.
Should-fix: the PR description doesn't mention the behaviour change for services disabled by an inactive profile. down --rmi local|all --remove-orphans used to remove their images, it now keeps them (consistent with isOrphaned, and without --remove-orphans they were already kept). Add a line to the description; the doc suggestion inline covers the code side.
Nits:
internal/images/prune.go:44-45: theRemoveOrphansdoc ("regardless of whether they are for a known service") is stale. Suggested text:
// RemoveOrphans will also remove the images built for the project that
// belong to no service of the model. A service that is declared but absent
// from the project given to the Pruner (disabled by a profile, or left out
// of the selection) is not an orphan: its images are kept.pkg/compose/down.go:201-203: the comment still describes the old "service no longer in the project" rule. Suggested text:
// a dangling image from a service outside the teardown set must be
// spared, and so must an orphan's unless RemoveOrphans is set, same as
// the tagged image is (imageBelongsToKnownService is ImagesToPrune's own
// check).pkg/compose/down.go:146-148: thereturn erris unreachable, every name inoptions.Serviceswas validated byGetServiceearlier indown()(Codecov flags these lines). If you keep the check, computeimageProjectright afteroptions.Services = services, guarded byoptions.Images != api.ImagePruneNone, so a failure can't happen after the containers are already removed.internal/images/prune_test.go:ImageBelongsToKnownServicehas no direct test. A small table (service enabled / disabled / undeclared / empty label, withremoveOrphanson and off) would pin the matrix without going through the mocks.
Document orphan image handling and test the pruning rules directly. Signed-off-by: Seyed Noorollah Aghayenoor <noorollah.aghayenoor@gmail.com>
glours
approved these changes
Nov 5, 2026
glours
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thanks for the contribution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 this PR does
Keep images of services outside the teardown selection when running
down --rmi local|all <service>. The loaded project also contains dependencies, so pruning it directly can remove their images after their containers are gone.Related issue
Fixes #14453
Changes made
--rmi local|all --remove-orphans, this also preserves images for services disabled by an inactive profile.Testing done
All checks ran in isolated Linux/arm64 containers with Go 1.26.10:
go test -race ./...passed.go build -o /out/docker-compose ./cmdpassed.golangci-lint run --timeout 10m --build-tags e2e ./...passed with v2.15.0 (zero issues).golangci-lint fmt --diffreported no differences in the changed Go files.TestDownImagesOfSelectedServicespassed against a disposable Docker Engine 29.9.2. The same test against the unchanged implementation failed because the dependency image was removed.After the review changes,
go test -race ./internal/images ./pkg/composepassed and lint reported zero issues.The full E2E suite, separate relay module, and other platforms were not tested.