How to Prevent My VM Disk from Filling Up with Docker Builds?
Asked by
CraftyGiraffe97
I've been experiencing an issue where my VM disk constantly fills up whenever I run `docker compose up --build` for the same two projects. Eventually, the builds fail because there's no more space on the disk, mainly due to a bunch of build caches piling up. I'm looking for a way to make Docker automatically clean up unused cached layers and images to prevent this from happening.
Answers
To tackle your disk space issue, you can automate the cleanup of old build artifacts using these commands: `docker container prune -f`, `docker image prune -af`, and `docker buildx prune -af`. Itโs also smart to restrict the cache size by adding a filter, like `docker buildx prune -af --filter "until=168h"` to remove older layers. If you want completely fresh builds without worrying about old layers, try `docker compose build --no-cache`, though keep in mind this will be slower. Itโs a good idea to set up a weekly cron job for these cleanups to keep your disk from filling up again.
Reply to this answer
If you're still facing disk issues after trying those commands, check out `docker system prune`. It essentially combines multiple cleanup options into one, which might simplify things for you. Itโs worth giving it a shot!
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions