Reputation: 1067
Is there a way to limit the number of exited containers on a host in general or (ideally) to specific images?
I have a cron job that runs daily to removed them but I'd like docker to handle it, if possible.
I can't just have the cron job run more often because developers like a few old copies of a container to check.
Upvotes: 1
Views: 66
Reputation: 3364
Docker does not support a limit for the number of exited containers. In fact, Docker does not support any form of garbage collection for stopped containers. However, there are third-party tools such as docker-gc that support garbage collection of old containers and unused images. However, docker-gc does not support a limit for the number of stopped containers as you requested.
If you want to write a script that solves your problem: docker inspect
gives you a FinishedAt
date for stopped containers. You can list all containers with a specific image, sort them by the finish date, and then remove all images that exceed your limit. The python module docker-py
might be useful for that.
Upvotes: 1