Merge pull request #14578 from mountkin/fix-rmi-image-not-found

don't allow deleting the image of running containers
This commit is contained in:
David Calavera 2015-07-16 18:02:51 -07:00
Родитель 8801906ced ce6410cd4c
Коммит 15cb7dfc9e
2 изменённых файлов: 27 добавлений и 1 удалений

Просмотреть файл

@ -151,7 +151,7 @@ func (daemon *Daemon) canDeleteImage(imgID string, force bool) error {
parent, err := daemon.Repositories().LookupImage(container.ImageID)
if err != nil {
if daemon.Graph().IsNotExist(err, container.ImageID) {
return nil
continue
}
return err
}

Просмотреть файл

@ -249,3 +249,29 @@ func (s *DockerSuite) TestRmiBlank(c *check.C) {
c.Fatalf("Expected error message not generated: %s", out)
}
}
func (s *DockerSuite) TestRmiContainerImageNotFound(c *check.C) {
// Build 2 images for testing.
imageNames := []string{"test1", "test2"}
imageIds := make([]string, 2)
for i, name := range imageNames {
dockerfile := fmt.Sprintf("FROM busybox\nMAINTAINER %s\nRUN echo %s\n", name, name)
id, err := buildImage(name, dockerfile, false)
c.Assert(err, check.IsNil)
imageIds[i] = id
}
// Create a long-running container.
dockerCmd(c, "run", "-d", imageNames[0], "top")
// Create a stopped container, and then force remove its image.
dockerCmd(c, "run", imageNames[1], "true")
dockerCmd(c, "rmi", "-f", imageIds[1])
// Try to remove the image of the running container and see if it fails as expected.
out, _, err := dockerCmdWithError(c, "rmi", "-f", imageIds[0])
if err == nil || !strings.Contains(out, "is using it") {
c.Log(out)
c.Fatal("The image of the running container should not be removed.")
}
}