'docker rmi -f IMAGE_ID' untag all names and delete the image

If an image has been tagged to multiple repos and tags, 'docker
rmi -f IMAGE_ID' will just untag one random repo instead of
untagging all and deleting the image. This patch implement
this. This commit is composed of:

        *untag all names and delete the image

        *add test to this feature

        *modify commandline/cli.md to explain this

Signed-off-by: Deng Guangxing <dengguangxing@huawei.com>
This commit is contained in:
Deng Guangxing
2015-04-11 09:24:21 +08:00
parent 418195a4fb
commit 795a58fb44
3 changed files with 74 additions and 13 deletions
+37
View File
@@ -77,6 +77,43 @@ func TestRmiTag(t *testing.T) {
logDone("rmi - tag,rmi - tagging the same images multiple times then removing tags")
}
func TestRmiImgIDForce(t *testing.T) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir '/busybox-test'")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
t.Fatalf("failed to create a container:%s, %v", out, err)
}
containerID := strings.TrimSpace(out)
runCmd = exec.Command(dockerBinary, "commit", containerID, "busybox-test")
out, _, err = runCommandWithOutput(runCmd)
if err != nil {
t.Fatalf("failed to commit a new busybox-test:%s, %v", out, err)
}
imagesBefore, _, _ := dockerCmd(t, "images", "-a")
dockerCmd(t, "tag", "busybox-test", "utest:tag1")
dockerCmd(t, "tag", "busybox-test", "utest:tag2")
dockerCmd(t, "tag", "busybox-test", "utest/docker:tag3")
dockerCmd(t, "tag", "busybox-test", "utest:5000/docker:tag4")
{
imagesAfter, _, _ := dockerCmd(t, "images", "-a")
if strings.Count(imagesAfter, "\n") != strings.Count(imagesBefore, "\n")+4 {
t.Fatalf("tag busybox to create 4 more images with same imageID; docker images shows: %q\n", imagesAfter)
}
}
out, _, _ = dockerCmd(t, "inspect", "-f", "{{.Id}}", "busybox-test")
imgID := strings.TrimSpace(out)
dockerCmd(t, "rmi", "-f", imgID)
{
imagesAfter, _, _ := dockerCmd(t, "images", "-a")
if strings.Contains(imagesAfter, imgID[:12]) {
t.Fatalf("rmi -f %s failed, image still exists: %q\n\n", imgID, imagesAfter)
}
}
logDone("rmi - imgID,rmi -f imgID delete all tagged repos of specific imgID")
}
func TestRmiTagWithExistingContainers(t *testing.T) {
defer deleteAllContainers()