mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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:
commit
15cb7dfc9e
2 changed files with 27 additions and 1 deletions
|
@ -151,7 +151,7 @@ func (daemon *Daemon) canDeleteImage(imgID string, force bool) error {
|
||||||
parent, err := daemon.Repositories().LookupImage(container.ImageID)
|
parent, err := daemon.Repositories().LookupImage(container.ImageID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if daemon.Graph().IsNotExist(err, container.ImageID) {
|
if daemon.Graph().IsNotExist(err, container.ImageID) {
|
||||||
return nil
|
continue
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,3 +249,29 @@ func (s *DockerSuite) TestRmiBlank(c *check.C) {
|
||||||
c.Fatalf("Expected error message not generated: %s", out)
|
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.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue