Docker: How to get your storage back?

arun@controller:~$ sudo docker system df
Images 15 0 2.674GB 2.674GB (100%)
Containers 0 0 0B 0B
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
# use -v for more details
docker system df

Big bang approach

docker system prune is the best way to clean up multiple types of objects at once. This approach does not bother about anything and straightway starts the cleanup.

$ docker system prune# include -a  to remove all unused images not just dangling ones.# You have an option of putting filter as well.$ docker image prune -a --filter "until=24h"

Controlled approach

Maybe you don't believe in the big bang, even I don't. I always love to perform things in a controlled fashion. Prune is again there to help.

$ docker image prune -a
$ docker container prune -a
$ docker network prune -a
$ docker volume prune -a

I - Command line!

When I want to stop all of the running containers and remove them.

$ docker stop $(sudo docker ps -aq) && sudo docker rm $(sudo docker ps -aq)
$ docker rmi $(sudo docker images -q)# dangling 
$ docker rmi $(docker images -f "dangling=true" -q)
$ docker volume rm $(docker volume ls -q -f dangling=true)
$ docker rm $(docker ps -qa --no-trunc --filter "status=exited")
$ cd /var/lib/docker
$ du -sh .

In quest of understanding How Systems Work !

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store