How to remove old and unused Docker images

前端 未结 26 1645
北恋
北恋 2020-11-22 11:28

When running Docker for a long time, there are a lot of images in system. How can I remove all unused Docker images at once safety to free up the storage?

In additio

26条回答
  •  萌比男神i
    2020-11-22 12:08

    @VonC already gave a very nice answer, but for completeness here is a little script I have been using---and which also nukes any errand Docker processes should you have some:

    #!/bin/bash
    
    imgs=$(docker images | awk '// { print $3 }')
    if [ "${imgs}" != "" ]; then
       echo docker rmi ${imgs}
       docker rmi ${imgs}
    else
       echo "No images to remove"
    fi
    
    procs=$(docker ps -a -q --no-trunc)
    if [ "${procs}" != "" ]; then
       echo docker rm ${procs}
       docker rm ${procs}
    else
       echo "No processes to purge"
    fi
    

提交回复
热议问题