raise an error if rmi -f with multiple tags and running container

Fixes https://github.com/docker/docker/issues/14116

Signed-off-by: Shijiang Wei <mountkin@gmail.com>
This commit is contained in:
Shijiang Wei 2015-06-23 18:38:50 +08:00
parent 7674f21686
commit 9f7698a637
2 changed files with 18 additions and 1 deletions

View file

@ -90,7 +90,7 @@ func (daemon *Daemon) imgDeleteHelper(name string, list *[]types.ImageDelete, fi
return nil
}
if len(repos) <= 1 || (len(repoAndTags) <= 1 && deleteByID) {
if len(repos) <= 1 || deleteByID {
if err := daemon.canDeleteImage(img.ID, force); err != nil {
return err
}

View file

@ -161,6 +161,23 @@ func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
}
}
// See https://github.com/docker/docker/issues/14116
func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c *check.C) {
dockerfile := "FROM busybox\nRUN echo test 14116\n"
imgID, err := buildImage("test-14116", dockerfile, false)
c.Assert(err, check.IsNil)
newTag := "newtag"
dockerCmd(c, "tag", imgID, newTag)
dockerCmd(c, "run", "-d", imgID, "top")
out, _, err := dockerCmdWithError(c, "rmi", "-f", imgID)
if err == nil || !strings.Contains(out, "stop it and retry") {
c.Log(out)
c.Fatalf("rmi -f should not delete image with running containers")
}
}
func (s *DockerSuite) TestRmiTagWithExistingContainers(c *check.C) {
container := "test-delete-tag"
newtag := "busybox:newtag"