Search code examples
dockercontainersdiskpsdata-cleaning

Remove docker images and containers that are taking disk space


I've been using Docker for a while... I usually the command "docker run" to run containers. Today, I had the problem of saving data to disk on a database:

No space left on device

According to various documentation online, the solution is to use the following command:

docker stop $(docker ps -a -q) docker rm $(docker ps -a -q)

However, it fails in a lot of entries... Is there a proper way to clean up containers and images?


Solution

  • The latest version of Docker supports the following command:

    $ docker rmi $(docker images -q --filter "dangling=true")
    

    The command will properly remove the images... This is described at https://www.calazan.com/docker-cleanup-commands/, and some comments from http://jimhoskins.com/2013/07/27/remove-untagged-docker-images.html.