How to remove Docker files

I have been using docker for a while in a project and thank god it exists. There is no need in installing many project dependencies. In this case this is a Ruby on Rails 3 project, yes very old.

Everything was fine until my root partition “/” was out of space! I thought to myself – “What the hell!? There are not many programs in this hard drive!”.
This happened when I was dumping some data into my local database , in this case MongoDB.

So I ran:

docker ps -a -s

…and saw that a lot of space was taken. Then I resolved to remove all containers and images:

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

The space went from 27.9GB to 24GB. That was something but not good enough as my /var partition still had massive docker files.

After some digging in the documentation and online search, I found this awesome solution:

docker volume ls -qf dangling=true | xargs -r docker volume rm

The result was astonishing! The occupied space went from 24GB to 8,4GB!

Next time I build something with docker, I will pass – -rm as it will remove intermediate containers after a successful build.

docker build --rm

Thank you for reading and until next Tuesday.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s