Reputation: 6039
Due to some internal issues, we need to remove unused images as soon as they become unused.
I do know it's possible to use Garbage collection but it doesn't offer strict policy as we need.
I've come across this solution but
I was thinking about setting a cron
job directly over the nodes to run docker prune
but I hope there is a better way
No idea if it makes a difference but we are using AKS
Upvotes: 3
Views: 5773
Reputation: 1
The only thing silly is your assumption about downloaded images as being the only culprit for hogging space. Many resources besides those will stick around and take up space, especially when doing docker builds over time. Lots of intermediate containers and images are not always cleaned up, especially following bad builds. Running a docker system prune all
on a regular basis will release those resource and the associated disk space, which is very helpful in situations where ephemeral disk storage is not so easily increased.
Upvotes: -1
Reputation: 54249
This doesn't really accomplish much since things will be re-downloaded if they are requested again. But if you insist on a silly thing, best bet is a DaemonSet that runs with the host docker control socket hostPath-mounted in and runs docker system prune
as you mentioned. You can't use a cron job so you need to write the loop yourself, probably just bash -c 'while true; do docker system prune && sleep 3600; done'
or something.
Upvotes: 3