Automated Docker Pruning

Problem/Justification
Old docker images and builds are not cleaned up automatically. I have found a couple TB used from old images and builds. I also found unexpected large anonymous volumes from accidentally missing a volume mapping that are not easily

Impact
I suspect I’m not the only one who has found a couple TB tied up in old images and builds…

User Story
The TrueNAS docker environment is presented as a “managed environment” but is missing periodic housecleaning tasks. I would like to be able to:

  • See and delete unused container images and anonymous volumes
  • Mark some images as being “pinned” – not upgradeable, not auto-cleanable
  • Set whether superseded images are removed as soon as a successful upgrade has occurred, or delay for X days, or not auto-cleaned / manual only
  • Anonymous volumes should not be auto-deleted, but the middleware should help us avoid unintended anonymous volumes by checking that all image VOLUME instructions have been mapped.
  • Clean the build cache automatically or manually.

wouldn’t a simple cronjob with docker system prune solve that problem?

A custom cronjob helps me but no one else, and there should be a supported mode of housekeeping.

docker system prune -a doesn’t give a lot of control over what is cleaned. You can use filters but that is more complexity that the system should manage.