diff --git a/daemon/image_delete.go b/daemon/image_delete.go index 78ba29ffae..adec34e3c9 100644 --- a/daemon/image_delete.go +++ b/daemon/image_delete.go @@ -70,7 +70,7 @@ func (daemon *Daemon) DeleteImage(eng *engine.Engine, name string, imgs *engine. if parsedTag != "" { tags = append(tags, parsedTag) } - } else if repoName != parsedRepo && !force { + } else if repoName != parsedRepo && !force && first { // the id belongs to multiple repos, like base:latest and user:test, // in that case return conflict return fmt.Errorf("Conflict, cannot delete image %s because it is tagged in multiple repositories, use -f to force", name) diff --git a/integration-cli/docker_cli_rmi_test.go b/integration-cli/docker_cli_rmi_test.go index 6e0a89449e..8bc43d93fb 100644 --- a/integration-cli/docker_cli_rmi_test.go +++ b/integration-cli/docker_cli_rmi_test.go @@ -124,3 +124,36 @@ MAINTAINER foo`) logDone("rmi - force delete with existing containers") } + +func TestRmiWithMultipleRepositories(t *testing.T) { + defer deleteAllContainers() + newRepo := "127.0.0.1:5000/busybox" + oldRepo := "busybox" + newTag := "busybox:test" + cmd := exec.Command(dockerBinary, "tag", oldRepo, newRepo) + out, _, err := runCommandWithOutput(cmd) + if err != nil { + t.Fatalf("Could not tag busybox: %v: %s", err, out) + } + cmd = exec.Command(dockerBinary, "run", "--name", "test", oldRepo, "touch", "/home/abcd") + out, _, err = runCommandWithOutput(cmd) + if err != nil { + t.Fatalf("failed to run container: %v, output: %s", err, out) + } + cmd = exec.Command(dockerBinary, "commit", "test", newTag) + out, _, err = runCommandWithOutput(cmd) + if err != nil { + t.Fatalf("failed to commit container: %v, output: %s", err, out) + } + cmd = exec.Command(dockerBinary, "rmi", newTag) + out, _, err = runCommandWithOutput(cmd) + if err != nil { + t.Fatalf("failed to remove image: %v, output: %s", err, out) + } + if !strings.Contains(out, "Untagged: "+newTag) { + t.Fatalf("Could not remove image %s: %s, %v", newTag, out, err) + } + + logDone("rmi - delete a image which its dependency tagged to multiple repositories success") + +}