Share Knowledge

Cleaning up your local Docker instance to save space and fix issues

Sunday, November 29, 2020

Word of warning:

The following operations are destructive.

They can potentially remove data that's stored in one of the containers.

Additionally, all the images you want to run need to be downloaded again.

DO NOT run these commands on a plane if you want to run or build based on an existing container again!

So, with that out of the way....

A while back, I saw that one of my Gists that I shared with a co-worker got quite some stars.

The fast and modern way

Since I initially created that Gist, Docker has added the system prune command that does basically the same as the other commands below.

You can see the vailable options:

docker system prune --help

I mostly run it like this:

docker system prune -f

The manual way

Stop all containers

docker stop `docker ps -qa`

Remove all containers

docker rm `docker ps -qa`

Remove all images

docker rmi -f `docker images -qa `

Remove all volumes

docker volume rm $(docker volume ls -qf)

Remove all networks

docker network rm `docker network ls -q`

After running this, your installation should now be all fresh and clean.

The following commands should not output any items:

docker ps -a
docker images -a 
docker volume ls

The following command show only show the default networks:

docker network ls

Don't hesitate to let me know if something seems off or if I missed something!


Have a question or comment?

Chandrashekar Gaajula
Chandrashekar Gaajula ·

Thanks for putting this together. Flowed real easy.