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:
parent
7674f21686
commit
9f7698a637
2 changed files with 18 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue