DEV Community

Cover image for Purge docker with fire
Julien Prugne for Webeleon

Posted on • Edited on

Purge docker with fire

On my development machines, I need docker most of the time...

The annoying parts are:

  • take a shit ton of place on my SSD for images and unused containers. Like 200GB
  • add a lot of virtual network interfaces.... around 50 useless interfaces polluting my computer.

I won't uninstall docker but I would like to remove all containers, all volumes, all networks, and all volumes.

Start by stopping all running containers.

sudo docker stop `docker ps -qa`
Enter fullscreen mode Exit fullscreen mode

then delete all containers (running and stopped)

sudo docker rm `docker ps -qa`
Enter fullscreen mode Exit fullscreen mode

then remove all networks not used by at least one container. None are left so we are removing all of them...

sudo docker network prune
Enter fullscreen mode Exit fullscreen mode

Now we will remove all the volumes:

sudo docker volume prune
Enter fullscreen mode Exit fullscreen mode

And finally, we can remove all the images:

sudo docker images prune
Enter fullscreen mode Exit fullscreen mode

Enjoy the space and silence.

ps: If you are only looking to remove unused resources go with sudo docker system prune

pps: If you are only looking to remove stopped container docker container prune -f thanks to Manuel Castellin for the tips.

Top comments (2)

Collapse
 
mcastellin profile image
Manuel Castellin

@webeleon great idea sharing these tips! Lots of people will enjoy some additional free space!

Also, as a quick daily cleanup you can use the following to "remove all stopped containers":

docker container prune -f
Collapse
 
bassochette profile image
Julien Prugne

Thanks.

I'll add that command to the memo