I'm using Docker Swarm for deployment, and with each release, new images are being created. Over time, the old images accumulate and eventually take up all the disk space. I'm looking for suggestions on how to automatically clean up outdated images, specifically those that haven't been used in months or are old release versions. What methods do you use for this?
3 Answers
I usually set up a cron job that runs `docker system prune` monthly. It's a simple way to clean up old images without much hassle. Also, I've heard of tools like Dokploy that might have their own cleanup features, but I haven't checked if it's just a wrapper around the system prune command or something more complex.
Just a heads up, the `--filter` option doesn't currently allow filtering by age or last time used. So it's best to double-check if what you're aiming for is supported. There’s an open issue on GitHub for this topic, which you can refer to here: [GitHub Issue#4237](https://github.com/moby/moby/issues/4237).
Honestly, you don't need to complicate things. Just create a cron job to handle the cleanup. In the past, I used to write detailed scripts to avoid accidentally removing important images, but Docker has improved significantly over the years. You can use the `--filter` option to fine-tune the clean-up based on age or last usage—just make sure to check the current capabilities of that filter!

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