Keep a clean Docker environment ๐Ÿงน

How to clean up your docker environment with docker prune it is not just a good practice but it could help you to reclaim large disk space back in my case I reclaimed almost 12gb ๐Ÿคฏ

Keep a clean Docker environment ๐Ÿงน
Photo by Verne Ho / Unsplash

Docker is a really great tool, and an essential one nowadays but it is easy that docker consumes a lot of space quickly if you doesn't do a regular maintenance to your installation,

TL;DR

Clean your docker installation by removing unused containers with docker rm <CONTAINER ID> or if you wanna go beyond use docker system prune -a

Purge Docker โš ๏ธ

In my case my root partition becoming up to almost 20gb, slowly it was growing and growing, when I realize that indeed was Docker who was consuming most of the space, what was my action do a purge.

docker system prune --volume -a

Above command will delete all stopped containers, networks not in use, images not used and all build cache! it is a nuclear option and damn the consequences! so use it under your own risk!

In my case it was OK as I don't have any sensitive data or important states in my docker environment, I just wanna reclaim back my disk space.

After that cleaning my root space turn down to 8,8gb ๐Ÿ˜ฎ ๐ŸŽ‰

Final tip

also you could just delete containers that are older that the time given with:

docker container prune --filter "until=24h"

Useful if you would like to conserve latest containers.

Source

  • Linux Format magazine October 2023 LXF307 p75