Skip to content

scrapinghub/docker-custodian

 
 

Repository files navigation

Docker Custodian

Keep docker hosts tidy.

Install

There are three installation options

Container

docker pull yelp/docker-custodian
docker run -ti \
    -v /var/run/docker.sock:/var/run/docker.sock \
    yelp/docker-custodian dcgc --help

Debian/Ubuntu package

First build the package (requires dh-virtualenv)

dpkg-buildpackage -us -uc

Then install it

dpkg -i ../docker-custodian_*.deb

Source

pip install git+https://github.com/Yelp/docker-custodian.git#egg=docker_custodian

dcgc

Remove old docker containers and docker images.

dcgc will remove stopped containers and unused images that are older than "max age" or images that have count of tags greater than a given threshold. Running containers, and images which are used by a container are never removed.

Maximum age can be specificied with any format supported by pytimeparse.

If max count of tags is specified - newer tags are kept and older are removed. If both max age and max count of tags is specified images are cleared if any of the limits is exceeded.

Example:

dcgc --max-container-age 3days --max-image-age 30days --max-tags-count 5

Prevent images from being removed

dcgc supports an image exclude list. If you have images that you'd like to keep around forever you can use the exclude list to prevent them from being removed.

--exclude-image
    Never remove images with this tag. May be specified more than once.

--exclude-image-file
    Path to a file which contains a list of images to exclude, one
    image tag per line.

You also can use basic pattern matching to exclude images with generic tags.

user/repositoryA:*
user/repositoryB:?.?
user/repositoryC-*:tag

dcstop

Stop containers that have been running for too long.

dcstop will docker stop containers where the container name starts with --prefix and it has been running for longer than --max-run-time.

Example:

dcstop --max-run-time 2days --prefix "projectprefix_"

Packages

No packages published

Languages

  • Python 99.0%
  • Makefile 1.0%