Skip to content

Commit

Permalink
Fix rmi -f removing multiple tags
Browse files Browse the repository at this point in the history
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 <[email protected]> (github: dmcgowan)
  • Loading branch information
dmcgowan committed Oct 28, 2015
1 parent 1c8ee61 commit 48e7f79
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions daemon/image_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions integration-cli/docker_cli_rmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,31 @@ func (s *DockerSuite) TestRmiWithMultipleRepositories(c *check.C) {
c.Assert(out, checker.Contains, "Untagged: "+newTag)
}

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)
c.Assert(out, checker.Contains, "Untagged: "+tag2)
c.Assert(out, checker.Not(checker.Contains), "Untagged: "+tag1)

// Check built image still exists
images, _ := dockerCmd(c, "images", "-a")
c.Assert(images, checker.Contains, imageName, check.Commentf("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
Expand Down

0 comments on commit 48e7f79

Please sign in to comment.