When running docker for some time on your local machine it accumulates quite some data and from time to time you might want to clean them up.

This is a collection of docker commands I found most useful in this context:

Clean Volumes

Cleans all volumes that are not used by any container.

docker volume rm $(docker volume ls -qf dangling=true)

Clean Images

Cleans all images that are not used by any running container. This includes old versions of images.

docker rmi $(docker images -qf dangling=true)

Clean exited and dead containers and their volumes

Cleanes all containers that are not currently running. The -v makes sure the associated volumes are deleted too.

Be sure you don’t need them any more!

docker rm -v $(docker ps -qf status=dead -f status=exited --no-trunc)

Update all docker images

Updates all locally available docker images

docker images --format "{{.Repository}}" --filter "dangling=false" | xargs -L1 docker pull

Delete all images containing XYZ

docker images --format "{{.Repository}}:{{.Tag}}" | grep XYZ | xargs -L1 docker rmi

Any other helpful docker commands that I missed? Let me know in the comments.