Sometimes you just need to clean up your whole docker environment. Is there an easy way to do this? As it turns out, yes. Here are a couple of handy commands to help you out:

Stop all running containers: Link to heading

docker stop $(docker ps -aq)

Remove all containers: Link to heading

docker rm $(docker ps -aq)

Remove all container images: Link to heading

docker rmi $(docker images -aq)

Another way to remove container images Link to heading

docker image prune -f

This second command is helpful when you only want to remove “dangling” (unused) container images.

Remove all volumes: Link to heading

docker volume prune

Hope that helps you out!

Note that docker volume prune may leave some volumes in place. For instance, volumes created by owncloud when started using docker compose up do not seem to be removed automatically, and you might have to clean those up by hand. On Ubuntu (and other linux systems), Docker volumes typically live at /var/lib/docker/volumes/, so you can take a look there to see if anything needs to be cleaned up by hand.