mirror of
https://github.com/docker/compose.git
synced 2025-04-08 17:05:13 +02:00
fix local image removal when compose down
is ran with --project-name
(#10558)
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
0e375a8c61
commit
0363d9260a
@ -223,6 +223,7 @@ func TestDownRemoveImages(t *testing.T) {
|
||||
|
||||
localImagesToBeRemoved := []string{
|
||||
"testproject-local-anonymous:latest",
|
||||
"local-named-image:latest",
|
||||
}
|
||||
for _, img := range localImagesToBeRemoved {
|
||||
// test calls down --rmi=local then down --rmi=all, so local images
|
||||
@ -238,7 +239,6 @@ func TestDownRemoveImages(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
otherImagesToBeRemoved := []string{
|
||||
"local-named-image:latest",
|
||||
"remote-image:latest",
|
||||
"registry.example.com/remote-image-tagged:v1.0",
|
||||
}
|
||||
|
@ -107,14 +107,8 @@ func (p *ImagePruner) ImagesToPrune(ctx context.Context, opts ImagePruneOptions)
|
||||
// removed from YAML)
|
||||
shouldPrune = true
|
||||
} else {
|
||||
// only prune the image if it belongs to a known service for the
|
||||
// project AND is either an implicitly-named, locally-built image
|
||||
// or `--rmi=all` has been specified.
|
||||
// TODO(milas): now that Compose labels the images it builds, this
|
||||
// makes less sense; arguably, locally-built but explicitly-named
|
||||
// images should be removed with `--rmi=local` as well.
|
||||
service, err := p.project.GetService(img.Labels[api.ServiceLabel])
|
||||
if err == nil && (opts.Mode == ImagePruneAll || service.Image == "") {
|
||||
// only prune the image if it belongs to a known service for the project.
|
||||
if _, err := p.project.GetService(img.Labels[api.ServiceLabel]); err == nil {
|
||||
shouldPrune = true
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user