All Projects → clockworksoul → Docker Gc Cron

clockworksoul / Docker Gc Cron

A Docker image that allows scheduled cleanup of unused Docker images, containers, and volumes.

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Docker Gc Cron

Docker Headless Vnc Container
Collection of Docker images with headless VNC environments
Stars: ✭ 1,176 (+1351.85%)
Mutual labels:  docker-image
Docker Ruby Node
🐳 Alpine Docker Image with latest versions of Ruby, Node.js and yarn installed. This Docker Image is actively maintained and updated regularly.
Stars: ✭ 74 (-8.64%)
Mutual labels:  docker-image
Docker Alpine Python Machinelearning
Small Docker image with Python Machine Learning tools (~180MB) https://hub.docker.com/r/frolvlad/alpine-python-machinelearning/
Stars: ✭ 76 (-6.17%)
Mutual labels:  docker-image
Docker Pxe
A virtualized implementation of PXE supported by DNSMasq
Stars: ✭ 72 (-11.11%)
Mutual labels:  docker-image
Openedx Docker
🐳 A best practice Docker image of Open edX
Stars: ✭ 74 (-8.64%)
Mutual labels:  docker-image
Docker Openldap Backup
A docker image to run OpenLDAP, and make periodic backups 🐳
Stars: ✭ 75 (-7.41%)
Mutual labels:  docker-image
Puppeteer Container
A GitHub Action / Docker image for Puppeteer, the Headless Chrome Node API
Stars: ✭ 72 (-11.11%)
Mutual labels:  docker-image
Tf Serving K8s Tutorial
A Tutorial for Serving Tensorflow Models using Kubernetes
Stars: ✭ 78 (-3.7%)
Mutual labels:  docker-image
Bareos
Docker image for Bareos
Stars: ✭ 74 (-8.64%)
Mutual labels:  docker-image
Homeland Docker
🚀 Deployment Homeland with Docker
Stars: ✭ 76 (-6.17%)
Mutual labels:  docker-image
Alpine Erlang
An alpine image with Erlang installed, intended for releases
Stars: ✭ 73 (-9.88%)
Mutual labels:  docker-image
Linuxgsm Docker
The Official LinuxGSM Docker image (experimental)
Stars: ✭ 73 (-9.88%)
Mutual labels:  docker-image
Libqsbr
QSBR and EBR library
Stars: ✭ 76 (-6.17%)
Mutual labels:  garbage-collection
Docker Nuxt
Docker image to run NUXT.js application in production mode
Stars: ✭ 71 (-12.35%)
Mutual labels:  docker-image
Bitnami Docker Ghost
Bitnami Docker Image for Ghost
Stars: ✭ 76 (-6.17%)
Mutual labels:  docker-image
Sas Container Recipes
A collection of recipes and other resources for building containers that include SAS Viya software.
Stars: ✭ 71 (-12.35%)
Mutual labels:  docker-image
Anchore Engine
A service that analyzes docker images and applies user-defined acceptance policies to allow automated container image validation and certification
Stars: ✭ 1,192 (+1371.6%)
Mutual labels:  docker-image
Docker Maven Plugin
A maven plugin to manage docker containers and images for integration tests.
Stars: ✭ 80 (-1.23%)
Mutual labels:  docker-image
Custom War Packager
Custom Jenkins WAR packager for Jenkins
Stars: ✭ 77 (-4.94%)
Mutual labels:  docker-image
Cabot Docker
Docker Images to build full cabot environment
Stars: ✭ 75 (-7.41%)
Mutual labels:  docker-image

docker-gc-cron

The docker-gc-cron container will periodically run the very excellent Spotify docker-gc script script to automatically clean up unused containers and images. It's particularly useful when deployed on systems onto which large numbers of Docker images and containers are built or pulled, such as CI nodes.

By default, the process will run each night at midnight, but the timing and other behaviors can be precisely specified using standard cron syntax. A docker-compose.yml file for this purpose can be found in the compose directory of this repository to simplify execution.

Installation tl;dr

$ wget https://raw.githubusercontent.com/clockworksoul/docker-gc-cron/master/compose/docker-gc-exclude
$ wget https://raw.githubusercontent.com/clockworksoul/docker-gc-cron/master/compose/docker-compose.yml
$ docker-compose up -d

This will pull and execute a docker-gc-cron image associated with your installed Docker daemon. By default, the garbage collection process will execute nightly at midnight, but this can be easily changed by modifying the CRON property (see below).

Yes, the docker-gc-exclude is necessary when using this docker-compose.yml file.

Supported Environmental Settings

The container understands all of the settings that are supported by docker-gc, as well as additional settings that can be used to modify the cleanup frequency.

Much of the following documentation is borrowed and modified directly from the docker-gc README.

All of the following environmental variables can also be used by getting and modifying the docker-compose.yml file.

Modifying the cleanup schedule

By default, the docker-gc-cron process will run nightly at midnight (cron "0 0 * * *"). This schedule can be overridden by using the CRON setting as follows:

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -e CRON="0 */6 * * *" clockworksoul/docker-gc-cron

Forcing deletion of images that have multiple tags

By default, docker will not remove an image if it is tagged in multiple repositories. If you have a server running Docker where this is the case, for example in CI environments where dockers are being built, re-tagged, and pushed, you can enable a force flag to override this default.

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -e FORCE_IMAGE_REMOVAL=1 clockworksoul/docker-gc-cron

Preserving a minimum number of images for every repository

You might want to always keep a set of the most recent images for any repository. For example, if you are continually rebuilding an image during development you would want to clear out all but the most recent version of an image. To do so, set the MINIMUM_IMAGES_TO_SAVE=1 environment variable. You can preserve any count of the most recent images, e.g. save the most recent 10 with MINIMUM_IMAGES_TO_SAVE=10.

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -e MINIMUM_IMAGES_TO_SAVE=3 clockworksoul/docker-gc-cron

Forcing deletion of containers

By default, if an error is encountered when cleaning up a container, Docker will report the error back and leave it on disk. This can sometimes lead to containers accumulating. If you run into this issue, you can force the removal of the container by setting the environment variable below:

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -e FORCE_CONTAINER_REMOVAL=1 clockworksoul/docker-gc-cron

Excluding Recently Exited Containers and Images From Garbage Collection

By default, docker-gc will not remove a container if it exited less than 3600 seconds (1 hour) ago. In some cases you might need to change this setting (e.g. you need exited containers to stick around for debugging for several days). Set the GRACE_PERIOD_SECONDS variable to override this default.

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -e GRACE_PERIOD_SECONDS=86400 clockworksoul/docker-gc-cron

This setting also prevents the removal of images that have been created less than GRACE_PERIOD_SECONDS seconds ago.

Cleaning up orphaned container volumes

Orphaned volumes that were created by containers that no longer exist can, over time, grow to take up a significant amount of disk space. By default, this process will leave any orphaned volumes untouched. However, to instruct the process to automatically clean up any dangling volumes using a docker volume rm $(docker volume ls -qf dangling=true) call after the docker-gc process has been executed, simply set the CLEAN_UP_VOLUMES value to 1.

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -e CLEAN_UP_VOLUMES=1 clockworksoul/docker-gc-cron

Dry run

By default, docker-gc will proceed with deletion of containers and images. To test your command-line options set the DRY_RUN variable to override this default.

docker run -d -v /var/run/docker.sock:/var/run/docker.sock -e DRY_RUN=1 clockworksoul/docker-gc-cron
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].