How to remove unused Docker resources

Search for a command to run...

No comments yet. Be the first to comment.
Introduction I run a large WhatsApp group and I often need to mention everyone in the group. But there are no real solutions for mentioning all members. WhatsApp does not natively do it, and there was a Firefox browser extension, but it was abandoned...

Introduction This past week I was toying around with the HTML5 canvas element, trying to join two images together. At first, it seemed fine, but when I tried to reload the website, it was a mess. One image would load, but the other wouldn't. Investig...

Introduction I have worked on projects that required the production and testing database to be the same. This could be because some features work in MariaDB, but not in SQLite. Or some bugs appear in MySQL, but not in PostgreSQL. When you're working ...

Introduction I'm going to explain how to build a free plan for your Laravel Spark Next application. I will be using Paddle as the payment gateway, but the steps are almost identical with Stripe. Best of all? No credit card required for the free plan....

Introduction Sometimes you end up deploying an application to Dokku and then realize that you want to revert the changes you made. In this tutorial we'll go over how to roll back a Dokku deployment. Before we start Preface Keep in mind that rolling ...

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 let's 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.
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.
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 if you want to remove EVERYTHING, just append --all at the end.
docker system prune --all
And voilà, 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!