Browse Source

Merge pull request #9204 from jfrazelle/9056-rmi

Fix for rmi throws error "no such id".
Michael Crosby 10 years ago
parent
commit
17dfa126ba
2 changed files with 23 additions and 0 deletions
  1. 3 0
      daemon/image_delete.go
  2. 20 0
      integration-cli/docker_cli_rmi_test.go

+ 3 - 0
daemon/image_delete.go

@@ -133,6 +133,9 @@ func (daemon *Daemon) canDeleteImage(imgID string, force bool) error {
 	for _, container := range daemon.List() {
 	for _, container := range daemon.List() {
 		parent, err := daemon.Repositories().LookupImage(container.Image)
 		parent, err := daemon.Repositories().LookupImage(container.Image)
 		if err != nil {
 		if err != nil {
+			if daemon.Graph().IsNotExist(err) {
+				return nil
+			}
 			return err
 			return err
 		}
 		}
 
 

+ 20 - 0
integration-cli/docker_cli_rmi_test.go

@@ -99,3 +99,23 @@ func TestRmiTagWithExistingContainers(t *testing.T) {
 
 
 	logDone("rmi - delete tag with existing containers")
 	logDone("rmi - delete tag with existing containers")
 }
 }
+
+func TestRmiForceWithExistingContainers(t *testing.T) {
+	image := "busybox-clone"
+	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "build", "--no-cache", "-t", image, "/docker-busybox")); err != nil {
+		t.Fatalf("Could not build %s: %s, %v", image, out, err)
+	}
+
+	if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "test-force-rmi", image, "/bin/true")); err != nil {
+		t.Fatalf("Could not run container: %s, %v", out, err)
+	}
+
+	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "rmi", "-f", image))
+	if err != nil {
+		t.Fatalf("Could not remove image %s:  %s, %v", image, out, err)
+	}
+
+	deleteAllContainers()
+
+	logDone("rmi - force delete with existing containers")
+}