Fix rmi -f removing multiple tags

When an image has multiple tags and rmi is called with force on a tag, only the single tag should be removed.
The current behavior is broken and removes all tags and the image.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
(cherry picked from commit 48e7f7963e142a0a45b583c5e65015d896c59433)
This commit is contained in:
Derek McGowan
2015-10-28 16:07:02 -07:00
committed by Tibor Vass
parent 75f6674b11
commit 22c2f04847
2 changed files with 36 additions and 0 deletions
+5
View File
@@ -84,6 +84,11 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I
daemon.EventsService.Log("untag", img.ID, "")
records = append(records, untaggedRecord)
// If has remaining references then untag finishes the remove
if daemon.repositories.HasReferences(img) {
return records, nil
}
removedRepositoryRef = true
} else {
// If an ID reference was given AND there is exactly one
+31
View File
@@ -253,6 +253,37 @@ func (s *DockerSuite) TestRmiWithMultipleRepositories(c *check.C) {
}
}
func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *check.C) {
testRequires(c, DaemonIsLinux)
imageName := "rmiimage"
tag1 := imageName + ":tag1"
tag2 := imageName + ":tag2"
_, err := buildImage(tag1,
`FROM scratch
MAINTAINER "docker"`,
true)
if err != nil {
c.Fatal(err)
}
dockerCmd(c, "tag", tag1, tag2)
out, _ := dockerCmd(c, "rmi", "-f", tag2)
if !strings.Contains(out, "Untagged: "+tag2) {
c.Fatalf("should contain Untagged: %s", tag2)
}
if strings.Contains(out, "Untagged: " + tag1) {
c.Fatalf("should not contain Untagged: %s", tag1)
}
// Check built image still exists
images, _ := dockerCmd(c, "images", "-a")
if !strings.Contains(images, imageName) {
c.Fatalf("Built image missing %q; Images: %q", imageName, images)
}
}
func (s *DockerSuite) TestRmiBlank(c *check.C) {
testRequires(c, DaemonIsLinux)
// try to delete a blank image name