
Have you ever had a full hard drive because of Docker? I had.
All the old Docker containers, images, and volumes take up so much space.
I used commands like docker stop $(docker ps -a -q) and docker rm $(docker ps -a -q) to remove all containers and images.
But newer Docker versions (Docker with API version 1.25+) have the handy prune command.
Use
docker versionto find out the versions of your client and daemon.
It cleans up all stopped containers, unused networks, dangling images, and the build cache.
The --volumes flag also removes all unused volumes. You can skip the "are you sure" prompt by using the -f or --force flag.
To clean your docker, first stop all running containers, then run prune:
docker container stop $(docker container ls -aq)
docker system prune --volumes
And voilá! You have a clean local Docker installation.
Bonus tips:
docker system dfuntil filter to only clean up stuff created more than, e.g., two days ago: docker system prune --filter "until=48h" (Docker API version 1.28+)docker container prune --filter "until=48h"