{"id":13416582,"url":"https://github.com/konstruktoid/docker-garby","last_synced_at":"2025-03-09T10:30:48.622Z","repository":{"id":82394277,"uuid":"45559955","full_name":"konstruktoid/docker-garby","owner":"konstruktoid","description":"Just another Docker maintenance script, managing garbage collection of Docker containers and images.","archived":true,"fork":false,"pushed_at":"2020-01-08T09:45:32.000Z","size":68,"stargazers_count":37,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-22T10:17:01.375Z","etag":null,"topics":["container","docker","garbage-collector","shellscript"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/konstruktoid.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"konstruktoid"}},"created_at":"2015-11-04T18:46:58.000Z","updated_at":"2024-10-10T13:05:40.000Z","dependencies_parsed_at":"2023-06-15T11:45:16.826Z","dependency_job_id":null,"html_url":"https://github.com/konstruktoid/docker-garby","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konstruktoid%2Fdocker-garby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konstruktoid%2Fdocker-garby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konstruktoid%2Fdocker-garby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konstruktoid%2Fdocker-garby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/konstruktoid","download_url":"https://codeload.github.com/konstruktoid/docker-garby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242679489,"owners_count":20168158,"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":["container","docker","garbage-collector","shellscript"],"created_at":"2024-07-30T21:01:01.388Z","updated_at":"2025-03-09T10:30:48.272Z","avatar_url":"https://github.com/konstruktoid.png","language":"Shell","funding_links":["https://github.com/sponsors/konstruktoid","https://ko-fi.com/konstruktoid"],"categories":["Development with Docker","Dev Tools"],"sub_categories":["Garbage Collection"],"readme":"= docker-garby\n\nimage::garby.jpg[Dinotrux character Garby]\n\nJust another Docker garbage collection script, written for Docker version 1.9\nand later.\n\n== Docker version post-2017\n\nYou should be using a Docker version released later than 2017 with the\nhttps://docs.docker.com/config/pruning/[docker prune] command available.\nIf you don't need to exclude containers or images, use that instead.\n\n== Running docker-garby\nYou can either run `docker-garby` as a shell script on systems using GNU\ncoreutils or in a link:Dockerfile[Docker container]. By default it will clean\nnon-running containers that has been inactive for more than one hour, images,\nvolumes and, if you're using Docker 1.13 or later, unused networks.\n\nDue to differences between BSD and GNU coreutils it is recommended that you\nrun `docker-garby` in a container if you're using macOS/Mac OS X, or\ninstall the `coreutils` and `binutils` packages using http://brew.sh/[Homebrew].\n\n== Configuration options\nThe configuration options may be set in the script itself or at runtime. +\n`maxSecondsOld=600 pullExcluded=no sh docker-garby.sh` will remove a finished\ncontainer older than 10 minutes and not pull excluded images. Excluded images\nare those you want to keep no matter what.\n\n[source]\n----\ndockerPrune=${dockerPrune:=no} # \u003c1\u003e\npruneOptions=${pruneOptions} # \u003c2\u003e\nexcludeImages=${excludeImages:=\"$(pwd)/docker-garby.exclude\"} # \u003c3\u003e\nlogFile='syslog' # \u003c4\u003e\nmaxSecondsOld=${maxSecondsOld:=3600} # \u003c5\u003e\nnetworkPrune=${networkPrune:=yes} # \u003c6\u003e\npullExcluded=${pullExcluded:=yes} # \u003c7\u003e\n----\n\n\u003c1\u003e If you want to use the internal prune option, available in Docker 1.13.\nNegates `maxSecondsOld` and `excludeImages`.\n\u003c2\u003e Configure `docker {container|system|network} prune` options,\nif Docker 17.04 or later.\n\u003c3\u003e Exclude the images listed in this file.\n\u003c4\u003e Write to syslog. `logFile='./docker-garby.log'` will write to a logfile,\nand the file name will be appended with `-$(date +%Y%m%d)`.\n\u003c5\u003e How old a container has to be in seconds before removing it.\n\u003c6\u003e Remove unused networks using the internal prune option, available in\nDocker 1.13.\n\u003c7\u003e Pull the latest version of the excluded images.\n\n\n=== Excluding images\nThe file available to `excludeImages` above, should contain either the name\nand version, a label (starting with `label:`) or the SHA256 digest\n(starting with `sha256:`).\n```sh\n$ cat docker-garby.exclude\nsha256:47cf20d8c26c46fff71be614d9f54997edacfe8d46d51769706e5aba94b16f2b\nkonstruktoid/nginx:latest\nlabel:konstruktoid\n```\n\n=== Ansible\nAn `docker-garby` Ansible playbook is available at https://github.com/konstruktoid/Ansible/blob/master/roles/docker-garby_container/tasks/docker-garby.yml[konstruktoid/Ansible].\n\n== Examples\n\n=== Shell\n\n```sh\n$ dockerPrune=yes pruneOptions=\"--filter until=1m\" sh docker-garby.sh\nDeleted Containers:\n8b8dfbad1a37b4fabcfa892974f5a255a6aaa8cef921cc323d637f35919d61e1\n\nTotal reclaimed space: 0B\nTotal reclaimed space: 0B\n\n$ sudo journalctl SYSLOG_IDENTIFIER=docker-garby\n...\nFeb 10 14:21:49 lab01 docker-garby[3484]: clientVersion: 18061\nFeb 10 14:21:49 lab01 docker-garby[3492]: dockerPrune: yes\nFeb 10 14:21:49 lab01 docker-garby[3500]: pruneOptions: --filter until=1m\nFeb 10 14:21:49 lab01 docker-garby[3508]: excludeImages: /home/vagrant/vagrant/docker-garby.exclude\nFeb 10 14:21:49 lab01 docker-garby[3516]: logFile: syslog\nFeb 10 14:21:49 lab01 docker-garby[3524]: maxSecondsOld: 3600\nFeb 10 14:21:49 lab01 docker-garby[3532]: pullExcluded: yes\nFeb 10 14:21:49 lab01 docker-garby[3540]: serverVersion: 18061\nFeb 10 14:21:49 lab01 docker-garby[3573]: Using docker container prune.\nFeb 10 14:21:49 lab01 docker-garby[3602]: Using docker system prune.\nFeb 10 14:21:49 lab01 docker-garby[3627]: No dangling volumes found.\nFeb 10 14:21:49 lab01 docker-garby[3635]: Using docker network prune.\n```\n\n```sh\n$ dockerPrune=yes sh docker-garby.sh\nDeleted Containers:\na2209b39ffdfbd305e1a940c2cced53aa4217f858508041015dcefcea9dc2a64\n550f1d001178d76d0a1fd4f0015aeb41f053fbadc291ec04996473f63778381f\n47a31c8b183d826b4608156666223e641f2d32628adb85380e3d4b622d18c22d\n8a21af9adc7c8b0432be3749e1073f55085a3161f233e5354098b1de56ffee78\n6dd02a7762927470228ab76046e70f7df1060b4bfbcdf74ad129f809cec53e27\n\nTotal reclaimed space: 0 B\nDeleted Images:\nuntagged: konstruktoid/privoxy:latest\nuntagged: konstruktoid/privoxy@sha256:0adaa06fffe2f7cdc80ad53e5ed62337fda54027f6fff5005d348c5f5d16818d\ndeleted: sha256:f4c8c0d866b641abc09825f2cfbf01d272cf4252ac21bca1009b4f041158f0c1\ndeleted: sha256:38548bee69829edec5a71dd5f2bd85878683977b2a9ef542061202d307ece4ca\ndeleted: sha256:0e0484753b293b8362ce8a91aee3cf201a6d9b1b7bac94f1b4f6dba2db14540c\ndeleted: sha256:a0e90e7c7eefc1ed0501f89ac9c6ac405a166be36214fa1ce0e3803177045f49\ndeleted: sha256:22b4595ae3d4e328621c70ef8dda5a9277f8404ee9b326a4ec78758b0e258de2\n\nTotal reclaimed space: 1.875 MB\n```\n\n```sh\n$ sh docker-garby.sh\n$ sudo journalctl SYSLOG_IDENTIFIER=docker-garby\n-- Logs begin at Wed 2016-07-13 01:26:04 CEST, end at Wed 2016-07-20 09:30:45 CEST. --\nJul 20 09:22:22 lab01 docker-garby[34525]: excludeImages: /home/tsj/Git/docker-garby/docker-garby.exclude\nJul 20 09:22:22 lab01 docker-garby[34531]: pullExcluded: yes\nJul 20 09:22:22 lab01 docker-garby[34537]: logFile: syslog\nJul 20 09:22:22 lab01 docker-garby[34543]: maxSecondsOld: 3600\nJul 20 09:22:22 lab01 docker-garby[34620]: Container /nostalgic_newton (08fd5995b8a1) finished 643403 seconds ago.\nJul 20 09:22:22 lab01 docker-garby[34626]: Container /nostalgic_newton (08fd5995b8a1) used image [].\nJul 20 09:22:22 lab01 docker-garby[34635]: Container /nostalgic_newton (08fd5995b8a1) removed.\nJul 20 09:22:23 lab01 docker-garby[34671]: Container /angry_roentgen (f020fe7f8108) finished 643479 seconds ago.\nJul 20 09:22:23 lab01 docker-garby[34677]: Container /angry_roentgen (f020fe7f8108) used image [].\nJul 20 09:22:23 lab01 docker-garby[34686]: Container /angry_roentgen (f020fe7f8108) removed.\nJul 20 09:22:23 lab01 docker-garby[34722]: Container /focused_kare (4c70871cae44) finished 643787 seconds ago.\nJul 20 09:22:23 lab01 docker-garby[34728]: Container /focused_kare (4c70871cae44) used image [].\nJul 20 09:22:23 lab01 docker-garby[34737]: Container /focused_kare (4c70871cae44) removed.\nJul 20 09:22:25 lab01 docker-garby[35074]: Container /hopeful_yalow (92bd220166ac) finished 1762378 seconds ago.\nJul 20 09:22:25 lab01 docker-garby[35080]: Container /hopeful_yalow (92bd220166ac) used image [konstruktoid/ubuntubuild:latest].\nJul 20 09:22:25 lab01 docker-garby[35089]: Container /hopeful_yalow (92bd220166ac) removed.\nJul 20 09:22:25 lab01 docker-garby[35124]: Container /desperate_lichterman (5614bd82697a) finished 1763270 seconds ago.\nJul 20 09:22:25 lab01 docker-garby[35130]: Container /desperate_lichterman (5614bd82697a) used image [yak:latest].\nJul 20 09:22:25 lab01 docker-garby[35139]: Container /desperate_lichterman (5614bd82697a) removed.\nJul 20 09:22:25 lab01 docker-garby[35189]: Container /infallible_ptolemy (e6d0737e4f3e) removed.\nJul 20 09:22:26 lab01 docker-garby[35225]: Container /drunk_euclid (e1dcc6a2dde2) finished 2112106 seconds ago.\nJul 20 09:22:26 lab01 docker-garby[35231]: Container /drunk_euclid (e1dcc6a2dde2) used image [nginx:latest].\nJul 20 09:22:26 lab01 docker-garby[35240]: Container /drunk_euclid (e1dcc6a2dde2) removed.\nJul 20 09:22:26 lab01 docker-garby[35266]: Image [alpine:3.3] (sha256:47cf20d8c26c46fff71be614d9f54997edacfe8d46d51769706e5aba94b16f2b) excluded.\nJul 20 09:22:33 lab01 docker-garby[35279]: Image [alpine:3.3] pulled.\nJul 20 09:22:33 lab01 docker-garby[35292]: Image [konstruktoid/nginx:latest] (sha256:fa15a419f9005114cae823a5ab1b5c123cf729edcbd11e4dff4f4ed3b957595f) excluded.\nJul 20 09:22:35 lab01 docker-garby[35304]: Image [konstruktoid/nginx:latest] pulled.\nJul 20 09:23:04 lab01 docker-garby[35386]: Image [debian:8 debian:latest] (sha256:1b088884749bd93867ddb48ff404d4bbff09a17af8d95bc863efa5d133f87b78) unused.\nJul 20 09:23:18 lab01 docker-garby[35395]: Image [debian:8 debian:latest] (sha256:1b088884749bd93867ddb48ff404d4bbff09a17af8d95bc863efa5d133f87b78) removed.\nJul 20 09:23:18 lab01 docker-garby[35423]: Image [busybox:latest] (sha256:2b8fd9751c4c0f5dd266fcae00707e67a2545ef34f9a29354585f93dac906749) unused.\nJul 20 09:23:19 lab01 docker-garby[35432]: Image [busybox:latest] (sha256:2b8fd9751c4c0f5dd266fcae00707e67a2545ef34f9a29354585f93dac906749) removed.\nJul 20 09:23:19 lab01 docker-garby[35442]: Image [centos:6.6] (sha256:2c886f766286449b76ad90a7ce577b988e48fe5a3ed9a75c53fb81f783946831) unused.\nJul 20 09:23:44 lab01 docker-garby[35452]: Image [centos:6.6] (sha256:2c886f766286449b76ad90a7ce577b988e48fe5a3ed9a75c53fb81f783946831) removed.\nJul 20 09:23:44 lab01 docker-garby[35462]: Image [fedora:22] (sha256:2d3da2084d089bc8405d040807290e0dd9d2b7eba747046e42650eddb6209a39) unused.\nJul 20 09:23:57 lab01 docker-garby[35472]: Image [fedora:22] (sha256:2d3da2084d089bc8405d040807290e0dd9d2b7eba747046e42650eddb6209a39) removed.\nJul 20 09:24:03 lab01 docker-garby[35499]: Image [ubuntu:14.04] (sha256:38c759202e30c0d088367425a0252634c3b401e77d547d16ea25d2af6836224d) unused.\nJul 20 09:24:22 lab01 docker-garby[35508]: Image [ubuntu:14.04] (sha256:38c759202e30c0d088367425a0252634c3b401e77d547d16ea25d2af6836224d) removed.\n```\n\n=== Docker\n```sh\n$ docker build --no-cache --tag konstruktoid/docker-garby -f Dockerfile .\n$ docker run --rm --read-only --tmpfs /tmp:rw,nosuid,nodev -v /var/run/docker.sock:/var/run/docker.sock konstruktoid/docker-garby\n[20160706141226] Container /silly_kilby6 (c2aa58249762) finished 3708 seconds ago.\n[20160706141226] Container /silly_kilby6 (c2aa58249762) used image [].\n[20160706141226] Container /silly_kilby6 (c2aa58249762) removed.\n[20160706141226] Container /elegant_lalande (ad385eee7dd8) finished 3737 seconds ago.\n[20160706141226] Container /elegant_lalande (ad385eee7dd8) used image [].\n[20160706141226] Container /elegant_lalande (ad385eee7dd8) removed.\n[20160706141226] Container /kickass_hoover (e053f8b2c3e6) finished 3759 seconds ago.\n[20160706141226] Container /kickass_hoover (e053f8b2c3e6) used image [konstruktoid/alpine:latest].\n[20160706141226] Container /kickass_hoover (e053f8b2c3e6) removed.\n[20160706141226] Image [konstruktoid/alpine:latest] (sha256:d879607f7403c3a12b1d5b0bc8d39e609d41be55b4a49923d33b08e897ad56de) excluded.\n[20160706141226] Image [nginx:latest] (sha256:0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca67d01a470d) excluded.\n[20160706141226] Image [] (sha256:16786a382fbb2334740de73eb0de534d760b281e0084a78802a076034e09aa72) unused.\n[20160706141226] Image [] (sha256:16786a382fbb2334740de73eb0de534d760b281e0084a78802a076034e09aa72) removed.\n[20160706141226] Image [alpine:3.3] (sha256:47cf20d8c26c46fff71be614d9f54997edacfe8d46d51769706e5aba94b16f2b) unused.\n[20160706141226] ERR: Image [alpine:3.3] (sha256:47cf20d8c26c46fff71be614d9f54997edacfe8d46d51769706e5aba94b16f2b) was not removed.\n[20160706141226] Image [] (sha256:83e46309df54bc729f68008d2bec6bcc272e1b5e2f3c6130731c0e8e525faf1c) unused.\n[20160706141226] Image [] (sha256:83e46309df54bc729f68008d2bec6bcc272e1b5e2f3c6130731c0e8e525faf1c) removed.\n[20160706141226] Image [] (sha256:e908192db440b9d621d89cd87f68bfd4e2e556785089da265d271454eb002c44) unused.\n[20160706141226] Image [] (sha256:e908192db440b9d621d89cd87f68bfd4e2e556785089da265d271454eb002c44) removed.\n[20160706141226] Image [] (sha256:ea4abdc85a28f70219a0d683c33f2438959f84dae3fe10ef5b964153a13fee33) unused.\n[20160706141226] Image [] (sha256:ea4abdc85a28f70219a0d683c33f2438959f84dae3fe10ef5b964153a13fee33) removed.\n[20160706141226] No dangling volumes found.\n```\n\n== Contributing\nDo you want to contribute? That's great! Contributions are always welcome,\nno matter how large or small. If you found something odd, feel free to\nhttps://github.com/konstruktoid/docker-garby/issues/[submit a new issue],\nimprove the code by https://github.com/konstruktoid/docker-garby/pulls[creating a pull request],\nor by https://ko-fi.com/konstruktoid[sponsoring this project].\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonstruktoid%2Fdocker-garby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkonstruktoid%2Fdocker-garby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonstruktoid%2Fdocker-garby/lists"}