Signed-off-by: Lei Jitang <leijitang@huawei.com>
| ... | ... |
@@ -70,7 +70,7 @@ func (daemon *Daemon) DeleteImage(eng *engine.Engine, name string, imgs *engine. |
| 70 | 70 |
if parsedTag != "" {
|
| 71 | 71 |
tags = append(tags, parsedTag) |
| 72 | 72 |
} |
| 73 |
- } else if repoName != parsedRepo && !force {
|
|
| 73 |
+ } else if repoName != parsedRepo && !force && first {
|
|
| 74 | 74 |
// the id belongs to multiple repos, like base:latest and user:test, |
| 75 | 75 |
// in that case return conflict |
| 76 | 76 |
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`) |
| 124 | 124 |
|
| 125 | 125 |
logDone("rmi - force delete with existing containers")
|
| 126 | 126 |
} |
| 127 |
+ |
|
| 128 |
+func TestRmiWithMultipleRepositories(t *testing.T) {
|
|
| 129 |
+ defer deleteAllContainers() |
|
| 130 |
+ newRepo := "127.0.0.1:5000/busybox" |
|
| 131 |
+ oldRepo := "busybox" |
|
| 132 |
+ newTag := "busybox:test" |
|
| 133 |
+ cmd := exec.Command(dockerBinary, "tag", oldRepo, newRepo) |
|
| 134 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 135 |
+ if err != nil {
|
|
| 136 |
+ t.Fatalf("Could not tag busybox: %v: %s", err, out)
|
|
| 137 |
+ } |
|
| 138 |
+ cmd = exec.Command(dockerBinary, "run", "--name", "test", oldRepo, "touch", "/home/abcd") |
|
| 139 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 140 |
+ if err != nil {
|
|
| 141 |
+ t.Fatalf("failed to run container: %v, output: %s", err, out)
|
|
| 142 |
+ } |
|
| 143 |
+ cmd = exec.Command(dockerBinary, "commit", "test", newTag) |
|
| 144 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 145 |
+ if err != nil {
|
|
| 146 |
+ t.Fatalf("failed to commit container: %v, output: %s", err, out)
|
|
| 147 |
+ } |
|
| 148 |
+ cmd = exec.Command(dockerBinary, "rmi", newTag) |
|
| 149 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 150 |
+ if err != nil {
|
|
| 151 |
+ t.Fatalf("failed to remove image: %v, output: %s", err, out)
|
|
| 152 |
+ } |
|
| 153 |
+ if !strings.Contains(out, "Untagged: "+newTag) {
|
|
| 154 |
+ t.Fatalf("Could not remove image %s: %s, %v", newTag, out, err)
|
|
| 155 |
+ } |
|
| 156 |
+ |
|
| 157 |
+ logDone("rmi - delete a image which its dependency tagged to multiple repositories success")
|
|
| 158 |
+ |
|
| 159 |
+} |