Skip to content

Commit 0363d92

Browse files
authored
fix local image removal when compose down is ran with --project-name (docker#10558)
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 0e375a8 commit 0363d92

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

pkg/compose/down_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ func TestDownRemoveImages(t *testing.T) {
223223

224224
localImagesToBeRemoved := []string{
225225
"testproject-local-anonymous:latest",
226+
"local-named-image:latest",
226227
}
227228
for _, img := range localImagesToBeRemoved {
228229
// test calls down --rmi=local then down --rmi=all, so local images
@@ -238,7 +239,6 @@ func TestDownRemoveImages(t *testing.T) {
238239
assert.NilError(t, err)
239240

240241
otherImagesToBeRemoved := []string{
241-
"local-named-image:latest",
242242
"remote-image:latest",
243243
"registry.example.com/remote-image-tagged:v1.0",
244244
}

pkg/compose/image_pruner.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,8 @@ func (p *ImagePruner) ImagesToPrune(ctx context.Context, opts ImagePruneOptions)
107107
// removed from YAML)
108108
shouldPrune = true
109109
} else {
110-
// only prune the image if it belongs to a known service for the
111-
// project AND is either an implicitly-named, locally-built image
112-
// or `--rmi=all` has been specified.
113-
// TODO(milas): now that Compose labels the images it builds, this
114-
// makes less sense; arguably, locally-built but explicitly-named
115-
// images should be removed with `--rmi=local` as well.
116-
service, err := p.project.GetService(img.Labels[api.ServiceLabel])
117-
if err == nil && (opts.Mode == ImagePruneAll || service.Image == "") {
110+
// only prune the image if it belongs to a known service for the project.
111+
if _, err := p.project.GetService(img.Labels[api.ServiceLabel]); err == nil {
118112
shouldPrune = true
119113
}
120114
}

0 commit comments

Comments
 (0)