How to remove unused Docker resources
Chances are that you've been running Docker for some time and found out that your system's storage is almost full.
This is completely normal as Docker bundles all the needed dependencies with each container and doesn't remove anything if you don't explicitly tell it to do so.
So lets learn how to prune unused and unnecessary images, containers, volumes and networks!
This tutorial will help you liberate space on your system without breaking anything in the process.
Before we start
We will be using the Docker CLI, so I expect you to be a bit familiar with it.
Otherwise just use
docker --help on the terminal and toy with it a little.
- A little bit of Docker knowledge
Remove all images that are not tagged or referenced by any container
docker image prune
Remove all stopped containers
docker container prune
Remove all volumes not used by at least one container
docker volume prune
Remove all networks not used by at least one container
docker network prune
To finalize, lets remove everything --but volumes-- with a single command.
docker system prune
If you want to remove volumes too, just append
--volumes at the end.
docker system prune --volumes
And voila, that removed every single resource that was unnecessary on your system!
You might find that some images can't be removed because they are used. In this case you want to remove the resource that is using it, most likely a container.
If you want to read more, please check out the official Docker guide to pruning.
If you have found this useful then you should follow me, I will be posting more interesting content! 🥰
Or support me financially. 💸
Today you have learned how to free up space on your system by removing Docker's unused images, containers, volumes and networks.
Let me know how much space you have recovered in the comments!