{"id":13416580,"url":"https://github.com/meltwater/docker-cleanup","last_synced_at":"2025-03-15T00:31:08.532Z","repository":{"id":30044431,"uuid":"33593575","full_name":"meltwater/docker-cleanup","owner":"meltwater","description":"DEPRECATED Automatic Docker image, container and volume cleanup","archived":true,"fork":false,"pushed_at":"2019-06-11T08:06:56.000Z","size":40,"stargazers_count":586,"open_issues_count":0,"forks_count":117,"subscribers_count":53,"default_branch":"master","last_synced_at":"2024-07-31T21:57:14.990Z","etag":null,"topics":["archived","deprecated","docker","obsolete"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meltwater.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-08T08:11:39.000Z","updated_at":"2024-04-24T13:28:55.000Z","dependencies_parsed_at":"2022-07-28T00:47:10.772Z","dependency_job_id":null,"html_url":"https://github.com/meltwater/docker-cleanup","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meltwater%2Fdocker-cleanup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meltwater%2Fdocker-cleanup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meltwater%2Fdocker-cleanup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meltwater%2Fdocker-cleanup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meltwater","download_url":"https://codeload.github.com/meltwater/docker-cleanup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243667720,"owners_count":20328032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["archived","deprecated","docker","obsolete"],"created_at":"2024-07-30T21:01:01.342Z","updated_at":"2025-03-15T00:31:08.237Z","avatar_url":"https://github.com/meltwater.png","language":"Shell","funding_links":[],"categories":["Development with Docker","Shell"],"sub_categories":["Garbage Collection"],"readme":"# DEPRECATED\nThis repository is no longer activiely maintained.\n\n---\n# Docker Cleanup\nThis image will periodically clean up exited containers and remove images and volumes that aren't in use by a\nrunning container. Based on [tutumcloud/image-cleanup](https://github.com/tutumcloud/image-cleanup) and\n[chadoe/docker-cleanup-volumes](https://github.com/chadoe/docker-cleanup-volumes) with some small fixes.\n\n**WARNING: This script will remove all exited containers, data-only containers and unused images unless you \ncarefully exclude them. Take care if you mount /var/lib/docker into the container since that will clean \nup all unused data volumes. If it's not compatible with your system or Docker version it may delete \nall your volumes, even from under running containers.**\n\nNormally any Docker containers that exit are still kept on disk until *docker rm -v* is used to clean\nthem up. Similarly any images that aren't used any more are kept around. For a cluster node that see\nlots of containers start and stop, large amounts of exited containers and old image versions can fill\nup the disk. A Jenkins build slave has the same issues, but can also suffer from SNAPSHOT images being\ncontinuously rebuilt and causing untagged \u003cnone\u003e images to be left around.\n\n## Environment Variables\nThe default parameters can be overridden by setting environment variables on the container using the **docker run -e** flag.\n\n * **CLEAN_PERIOD=1800** - Interval in seconds to sleep after completing a cleaning run. Defaults to 1800 seconds = 30 minutes.\n * **DELAY_TIME=1800** - Seconds to wait before removing exited containers and unused images. Defaults to 1800 seconds = 30 minutes.\n * **KEEP_IMAGES** - List of images to avoid cleaning, e.g. \"ubuntu:trusty, ubuntu:latest\". Defaults to clean all unused images.\n * **KEEP_CONTAINERS** - List of images for exited or dead containers to avoid cleaning, e.g. \"ubuntu:trusty, ubuntu:latest\".\n * **KEEP_CONTAINERS_NAMED** - List of names for exited or dead containers to avoid cleaning, e.g. \"my-container1, persistent-data\".\n * **LOOP** - Add the ability to do non-looped cleanups, run it once and exit. Options are true, false. Defaults to true to run it forever in loops.\n * **DEBUG** - Set to 1 to enable more debugging output on pattern matches\n * **DOCKER_API_VERSION** - The docker API version to use. This defaults to 1.20, but you can override it here in case the docker version on your host differs from the one that is installed in this container. You can find this on your host system by running `docker version --format '{{.Client.APIVersion}}'`.\n\nNote that **KEEP_IMAGES**, **KEEP_CONTAINERS**, and **KEEP_CONTAINERS_NAMED** are left-anchored bash shell pattern matching lists (NOT regexps).  Therefore, the image **foo/bar:tag** will be matched by ANY of the following:\n\n * foo/bar:tag\n * foo/bar\n * foo/b\n * [[:alpha:]]/bar\n * \\*/\\*:tag\n * \\*:tag\n * foo/\\*:tag\n\nHowever it will not match\n\n * foo/baz\n * bar:tag\n * /bar\n * :tag\n * [[:alpha:]]:tag\n\nBy default, both are set to **\\*\\*None\\*\\*** which is the same as the blank string.  If you want to keep ALL images or containers, effectively disabling this \npart of the cleanup, then you should use **\\*:\\*** to match all images.  Do not \nuse a bare **\\*** as this will be taken as a filename match.\n\n## Deployment\nThe image uses the Docker client to to list and remove containers and images. For this reason the Docker client and socket is mapped into the container.\n\nIf the */var/lib/docker* directory is mapped into the container this script will also clean up orphaned Docker volumes.\n\n### Systemd and CoreOS/Fleet\n\nCreate a [Systemd unit](http://www.freedesktop.org/software/systemd/man/systemd.unit.html) file\nin **/etc/systemd/system/docker-cleanup.service** with contents like below. Using CoreOS and\n[Fleet](https://coreos.com/docs/launching-containers/launching/fleet-unit-files/) then\nadd the X-Fleet section to schedule the unit on all cluster nodes.\n\n```\n[Unit]\nDescription=Cleanup of exited containers and unused images/volumes\nAfter=docker.service\nRequires=docker.service\n\n[Install]\nWantedBy=multi-user.target\n\n[Service]\nEnvironment=IMAGE=meltwater/docker-cleanup:latest NAME=docker-cleanup\n\n# Allow docker pull to take some time\nTimeoutStartSec=600\n\n# Restart on failures\nKillMode=none\nRestart=always\nRestartSec=15\n\nExecStartPre=-/usr/bin/docker kill $NAME\nExecStartPre=-/usr/bin/docker rm $NAME\nExecStartPre=-/bin/sh -c 'if ! docker images | tr -s \" \" : | grep \"^${IMAGE}:\"; then docker pull \"${IMAGE}\"; fi'\nExecStart=/usr/bin/docker run \\\n    -v /var/run/docker.sock:/var/run/docker.sock:rw \\\n    -v /var/lib/docker:/var/lib/docker:rw \\\n    --name=${NAME} \\\n    $IMAGE\n\nExecStop=/usr/bin/docker stop $NAME\n\n[X-Fleet]\nGlobal=true\n```\n\n\n\n### Puppet Hiera\n\nUsing the [garethr-docker](https://github.com/garethr/garethr-docker) module\n\n```\nclasses:\n  - docker::run_instance\n\ndocker::run_instance:\n  'cleanup':\n    image: 'meltwater/docker-cleanup:latest'\n    volumes:\n      - \"/var/run/docker.sock:/var/run/docker.sock:rw\"\n      - \"/var/lib/docker:/var/lib/docker:rw\"\n```\n\n### Command Line\n```\ndocker run \\\n  -v /var/run/docker.sock:/var/run/docker.sock:rw \\\n  -v /var/lib/docker:/var/lib/docker:rw \\\n  meltwater/docker-cleanup:latest\n```\n\n### Kubernetes\n\nYou can find a Kubernetes `DaemonSet` configuration, that will allow you to run the `meltwater/docker-cleanup` container on every node of your cluster.\n\n```\nkubectl create -f contrib/k8s-daemonset.yml\n```\n\n### Development\n\nA ``Makefile`` is included to help with repetitive commands during development.\n\n```\nmake help\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeltwater%2Fdocker-cleanup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeltwater%2Fdocker-cleanup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeltwater%2Fdocker-cleanup/lists"}