I started using Docker recently at work. I had to build lot of docker images for my Rails app. After few days, on one fine morning I was building a brand new docker image and my laptop just froze.
On inspecting the disk size, I noticed that Docker was eating almost 90% of disk space. Fortunately, we can clear the unused space used by Docker very easily.
Find out unused Docker images
Unused Docker images are basically not connected to any of the tagged Docker images. We tag every Docker image to latest tag and push it to Docker Hub. So if we build two images back to back, the latest tag is applied to the most recent one and the older image becomes untagged.
Such unlinked images just consume space and are of no use.
In Docker parlance, such images are called dangling images.
We can find out such images by running this command.
docker images -f "dangling=true" -q
Remove dangling Docker images
Once we find them, just destroy them without a second thought.
docker rmi -f $(docker images -f "dangling=true" -q)
In my experience, just doing this reclaimed most of the wasted disk space. But if you are still facing issues, you can list all the docker images and then selectively delete them.
docker images
docker rmi <id>
Following this trick, I was able to rescue my laptop and use it normally with peace.
Top comments (2)
Just use docker system prune or docker system prune -a
Sorry no formatting I’m on mobile
Thanks Oscar, it just works!