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.
2 Answers
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!
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.

Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures