Docker: How to delete all local Docker images

后端 未结 16 2184
梦谈多话
梦谈多话 2021-01-29 17:24

I recently started using Docker and never realized that I should use docker-compose down instead of ctrl-c or docker-compose stop to get r

相关标签:
16条回答
  • 2021-01-29 17:44

    To delete all Docker local Docker images follow 2 steps ::

    step 1 : docker images ( list all docker images with ids )

         example :
         REPOSITORY    TAG    IMAGE ID            CREATED             SIZE
         pradip564/my  latest 31e522c6cfe4        3 months ago        915MB
    

    step 2 : docker image rm 31e522c6cfe4 ( IMAGE ID)

          OUTPUT : image deleted
    
    0 讨论(0)
  • 2021-01-29 17:47

    Another way with xargs

    docker image ls -q | xargs -I {} docker image rm -f {}
    
    0 讨论(0)
  • 2021-01-29 17:48
    1. sudo docker images / docker images // list of images with id
    2. sudo docker rm image <image_id> / docker rm image <image_id>
    0 讨论(0)
  • 2021-01-29 17:48

    Here is the command I used and put it in a batch file to remove everything:

    echo "Removing containers :" && if [ -n "$(docker container ls -aq)" ]; then docker container stop $(docker container ls -aq); docker container rm $(docker container ls -aq); fi; echo "Removing images :" && if [ -n "$(docker images -aq)" ]; then docker rmi -f $(docker images -aq); fi; echo "Removing volumes :" && if [ -n "$(docker volume ls -q)" ]; then docker volume rm $(docker volume ls -q); fi; echo "Removing networks :" && if [ -n "$(docker network ls | awk '{print $1" "$2}' | grep -v 'ID|bridge|host|none' | awk '{print $1}')" ]; then docker network rm $(docker network ls | awk '{print $1" "$2}' | grep -v 'ID|bridge|host|none' | awk '{print $1}'); fi;

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