How to remove multiple docker images with the same imageID?

后端 未结 8 2106
余生分开走
余生分开走 2021-01-30 20:15

I created a local docker registry and then pull some of my docker images from docker hub and then push them to the local registry. Now I want to remove my local images. But the

相关标签:
8条回答
  • 2021-01-30 20:55

    Here is one way :

    Repository and tag data can be provided to "docker rmi" command to remove image if images id are same.

    command

    docker rmi [repository_name1]:[tag1] [repository_name2]:[tag2]
    

    example

    docker rmi test-nginx:latest ubuntu:latest
    

    Note : one needs to name and tag the image appropriately to use the above command effectively for requirement mentioned in the question.

    Refer Docker docs for "docker rmi" command help : here

    0 讨论(0)
  • 2021-01-30 21:06

    Short Answer:

    Remove it by id and use -f flag:

    $ docker rmi -f fd484f19954f
    
    Untagged: test1:latest
    Untagged: test2:latest
    Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
    

    Explanation

    These are not multiple images with same id. This is actually one image that is referenced in multiple repositories (i.e. given multiple names/tags). This scenario is described exactly in rmi command documentation

    You can remove an image using its short or long ID, its tag, or its digest. If an image has one or more tag referencing it, you must remove all of them before the image is removed. Digest references are removed automatically when an image is removed by tag.

    Given,

    $ docker images
    
    REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
    test1                     latest              fd484f19954f        23 seconds ago      7 B (virtual 4.964 MB)
    test2                     latest              fd484f19954f        23 seconds ago      7 B (virtual 4.964 MB)
    

    You can, as an alternative to the short answer above, remove tags one by one (the last tag will actually remove the image too):

    $ docker rmi test1:latest
    
    Untagged: test1:latest
    
    $ docker rmi test2:latest
    
    Untagged: test2:latest
    Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
    
    0 讨论(0)
提交回复
热议问题