Merge pull request #11011 from coolljt0725/fix_rmi_conflict
Fix docker remove an image show misleading conflicts
This commit is contained in:
commit
13030add69
2 changed files with 34 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue