Fix for docker eats up disk space
We use Docker Desktop in our daily lives, but we often forget to maintain a few things. As a result, the Docker Desktop application almost uses up disk space. Sometimes, this application is completely corrupted and fails to start even after a system restart. This is very common. To prevent this, there are a few things we need to check.
If you can open Docker Desktop, it’s very good, and your data will not be deleted. There is an extension named “Disk usage“. You can install it to watch with a graphical interface. It will tell you where your disk was used. A typical screenshot is like the one below. You can reclaim space with a button click.
But remember, you are choosing the correct options while reclaiming space.
- Stopped containers: If you have an important container that is currently turned off, it will be deleted.
- Unused images: If you have any images that are not connected to any container, they will be deleted.
- Dangling images: They are safe to remove. They were created in some build stages and have no tag or name.
- Build cache records: These can also be removed, and all your build cache will be deleted.
- Unused volumes: Select this if you are sure. Any volume not connected to any container will be deleted.
Manual way
I would say go with the manual way; it is risk-free.
- Remove unnecessary containers: Go to the application and click the “Containers” button. Delete any unnecessary containers.
- Remove unused images: Go to the application and click the “Images” button. Delete any unused docker images.
- Remove unused volumes: Go to the application and click the “Volumes” button. Delete any unused docker volumes.
- Remove dangling images: With a terminal run:
docker rmi $(docker images -f "dangling=true" -q)
- Remove build cache: With a terminal run:
docker builder prune -a
.
The good news is that Docker Desktop recently released version 4.34.0, which has a new capability for Windows. Windows now supports automatic reclamation of disk space in Docker Desktop for WSL2 installations. You can read the release note here: https://docs.docker.com/desktop/release-notes/#4340
The Docker Desktop is completely corrupted.
When your docker desktop is completely corrupted, and you cannot open even after a system restarts, you can follow these steps:
- Uninstall the Docker Desktop.
- On Windows, run a command from a Power Shell:
wsl --unregister docker-desktop-data
. - On Windows, delete folder “C:\Users\<YourUserName>\AppData\Docker”.
- Restart your system.
- Fresh install Docker Desktop.
If you are still having problems, please add a comment with your details. I can then try to help you further.