How can I delete Docker's images?

后端 未结 17 1106
执笔经年
执笔经年 2020-11-29 14:27

I\'ve the following images:

alex@alexvps:~$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
&         


        
相关标签:
17条回答
  • 2020-11-29 15:15

    Use

    docker image prune -all
    

    or

    docker image prune -a
    

    Remove all dangling images. If -a is specified, it will also remove all images not referenced by any container.

    Note: You are prompted for confirmation before the prune removes anything, but you are not shown a list of what will potentially be removed. In addition, docker image ls does not support negative filtering, so it difficult to predict what images will actually be removed.

    As stated under Docker's documentation for prune.

    0 讨论(0)
  • 2020-11-29 15:20

    In order to delete all images, use the given command

    docker rmi $(docker images -q)
    

    In order to delete all containers, use the given command

    docker rm $(docker ps -a -q)
    

    Warning: This will destroy all your images and containers. It will not be possible to restore them!

    This solution is provided by Techoverflow.net.

    0 讨论(0)
  • 2020-11-29 15:21

    I found the answer in this command:

    docker images --no-trunc | grep none | awk '{print $3}' | xargs docker rmi
    

    I had your problem when I deleted some images that were being used, and I didn't realise (using docker ps -a).

    0 讨论(0)
  • 2020-11-29 15:22

    First, remove all the containers using the following command

    sudo docker ps -a -q | xargs -n 1 -I {} sudo docker rm {}
    

    Then, remove the image by its ID using the following command

    sudo docker rmi <image-id>
    
    0 讨论(0)
  • 2020-11-29 15:22

    I have found a solution with Powershell script that will do it for me.

    The script at first stop all containers than remove all containers and then remove images that are named by the user.

    Look here http://www.devcode4.com/article/powershell-remove-docker-containers-and-images

    0 讨论(0)
提交回复
热议问题