Fix rmi by ID untagging image on error

Do not untag image if it would later get a hard conflict because of running containers.

Fixes #18873

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Upstream-commit: 38a45eed8850a15d2f737ce7455f29c5ae53ab49
Component: engine
This commit is contained in:
Tonis Tiigi
2016-01-12 13:45:40 -08:00
parent 41680fdf37
commit f00ac953d1
2 changed files with 26 additions and 5 deletions
@@ -337,3 +337,20 @@ func (s *DockerSuite) TestRmiWithParentInUse(c *check.C) {
dockerCmd(c, "rmi", imageID)
}
// #18873
func (s *DockerSuite) TestRmiByIDHardConflict(c *check.C) {
testRequires(c, DaemonIsLinux)
dockerCmd(c, "create", "busybox")
imgID, err := inspectField("busybox:latest", "Id")
c.Assert(err, checker.IsNil)
_, _, err = dockerCmdWithError("rmi", imgID[:12])
c.Assert(err, checker.NotNil)
// check that tag was not removed
imgID2, err := inspectField("busybox:latest", "Id")
c.Assert(err, checker.IsNil)
c.Assert(imgID, checker.Equals, imgID2)
}