Cron Job to remove dangling docker images

I am looking at setting up the following command as a cron job. The purpose of this command is to remove old containers that are no longer needed by Discourse. It will automatically manage my docker space consumption.

docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi

The filter will only list docker images listed as <none> <none>. Then it will delete the images. This is set up to be run silently without human interaction.

As anyone else done this? Any gotchas or oh crap moments I need to be aware of?

or is there a better way?

Those files are never generated automatically, so there’s no reason for cron to do it. If you think you want to clean up images, then just do it after every rebuild.

1 Like

Preferences. I will forget to clean up the files after a rebuild. This way, I don’t have to remember a manual task.