mirror of
https://github.com/docker/compose.git
synced 2025-05-02 21:50:15 +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{
|
localImagesToBeRemoved := []string{
|
||||||
"testproject-local-anonymous:latest",
|
"testproject-local-anonymous:latest",
|
||||||
|
"local-named-image:latest",
|
||||||
}
|
}
|
||||||
for _, img := range localImagesToBeRemoved {
|
for _, img := range localImagesToBeRemoved {
|
||||||
// test calls down --rmi=local then down --rmi=all, so local images
|
// 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)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
otherImagesToBeRemoved := []string{
|
otherImagesToBeRemoved := []string{
|
||||||
"local-named-image:latest",
|
|
||||||
"remote-image:latest",
|
"remote-image:latest",
|
||||||
"registry.example.com/remote-image-tagged:v1.0",
|
"registry.example.com/remote-image-tagged:v1.0",
|
||||||
}
|
}
|
||||||
|
@ -107,14 +107,8 @@ func (p *ImagePruner) ImagesToPrune(ctx context.Context, opts ImagePruneOptions)
|
|||||||
// removed from YAML)
|
// removed from YAML)
|
||||||
shouldPrune = true
|
shouldPrune = true
|
||||||
} else {
|
} else {
|
||||||
// only prune the image if it belongs to a known service for the
|
// only prune the image if it belongs to a known service for the project.
|
||||||
// project AND is either an implicitly-named, locally-built image
|
if _, err := p.project.GetService(img.Labels[api.ServiceLabel]); err == nil {
|
||||||
// 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 == "") {
|
|
||||||
shouldPrune = true
|
shouldPrune = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user