2015-06-30 22:32:54 +00:00
|
|
|
Docker Custodian
|
|
|
|
================
|
|
|
|
|
2015-07-14 20:11:43 +00:00
|
|
|
.. image:: https://travis-ci.org/Yelp/docker-custodian.svg
|
|
|
|
:target: https://travis-ci.org/Yelp/docker-custodian
|
|
|
|
|
2015-07-10 19:52:21 +00:00
|
|
|
Keep docker hosts tidy.
|
2015-06-30 22:32:54 +00:00
|
|
|
|
|
|
|
|
2015-08-08 20:26:36 +00:00
|
|
|
.. contents::
|
|
|
|
:backlinks: none
|
|
|
|
|
2015-08-08 22:11:22 +00:00
|
|
|
Install
|
|
|
|
-------
|
|
|
|
|
|
|
|
There are three installation options
|
|
|
|
|
|
|
|
Container
|
|
|
|
~~~~~~~~~
|
|
|
|
|
|
|
|
.. code::
|
|
|
|
|
2015-09-29 17:57:23 +00:00
|
|
|
docker pull yelp/docker-custodian
|
2015-09-01 01:31:14 +00:00
|
|
|
docker run -ti \
|
|
|
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
2015-09-29 17:57:23 +00:00
|
|
|
yelp/docker-custodian dcgc --help
|
2015-08-08 22:11:22 +00:00
|
|
|
|
|
|
|
Debian/Ubuntu package
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
First build the package (requires `dh-virtualenv`)
|
|
|
|
|
|
|
|
.. code:: sh
|
|
|
|
|
|
|
|
dpkg-buildpackage -us -uc
|
|
|
|
|
|
|
|
Then install it
|
|
|
|
|
|
|
|
.. code:: sh
|
|
|
|
|
|
|
|
dpkg -i ../docker-custodian_*.deb
|
|
|
|
|
|
|
|
|
|
|
|
Source
|
|
|
|
~~~~~~
|
|
|
|
|
|
|
|
.. code:: sh
|
|
|
|
|
2016-04-20 21:11:35 +00:00
|
|
|
pip install git+https://github.com/Yelp/docker-custodian.git#egg=docker_custodian
|
2015-08-08 20:26:36 +00:00
|
|
|
|
|
|
|
|
2015-06-30 22:32:54 +00:00
|
|
|
dcgc
|
|
|
|
----
|
|
|
|
|
|
|
|
Remove old docker containers and docker images.
|
|
|
|
|
|
|
|
``dcgc`` will remove stopped containers and unused images that are older than
|
|
|
|
"max age". Running containers, and images which are used by a container are
|
|
|
|
never removed.
|
|
|
|
|
|
|
|
Maximum age can be specificied with any format supported by
|
|
|
|
`pytimeparse <https://github.com/wroberts/pytimeparse>`_.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2015-08-08 20:26:36 +00:00
|
|
|
.. code:: sh
|
|
|
|
|
2015-06-30 22:32:54 +00:00
|
|
|
dcgc --max-container-age 3days --max-image-age 30days
|
|
|
|
|
|
|
|
|
2015-07-16 19:26:06 +00:00
|
|
|
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.
|
|
|
|
|
2015-08-08 20:26:36 +00:00
|
|
|
::
|
|
|
|
|
2015-07-16 19:26:06 +00:00
|
|
|
--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.
|
|
|
|
|
2016-10-04 09:23:40 +00:00
|
|
|
You also can use basic pattern matching to exclude images with generic tags.
|
2015-07-16 19:26:06 +00:00
|
|
|
|
2016-10-04 09:23:40 +00:00
|
|
|
.. code::
|
|
|
|
|
|
|
|
user/repositoryA:*
|
|
|
|
user/repositoryB:?.?
|
|
|
|
user/repositoryC-*:tag
|
2015-07-16 19:26:06 +00:00
|
|
|
|
2018-03-06 23:21:36 +00:00
|
|
|
|
|
|
|
Prevent containers and associated images from being removed
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
``dcgc`` also supports a container exclude list based on labels. If there are
|
|
|
|
stopped containers that you'd like to keep, then you can check the labels to
|
|
|
|
prevent them from being removed.
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
--exclude-container-label
|
|
|
|
Never remove containers that have the label key=value. =value can be
|
|
|
|
omitted and in that case only the key is checked. May be specified
|
|
|
|
more than once.
|
|
|
|
|
|
|
|
You also can use basic pattern matching to exclude generic labels.
|
|
|
|
|
|
|
|
.. code::
|
|
|
|
|
|
|
|
foo*
|
|
|
|
com.docker.compose.project=test*
|
|
|
|
com.docker*=*bar*
|
|
|
|
|
|
|
|
|
2015-06-30 22:32:54 +00:00
|
|
|
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:
|
|
|
|
|
2015-08-08 20:26:36 +00:00
|
|
|
.. code:: sh
|
|
|
|
|
2015-06-30 22:32:54 +00:00
|
|
|
dcstop --max-run-time 2days --prefix "projectprefix_"
|