{"id":2047,"date":"2023-03-27T11:18:19","date_gmt":"2023-03-27T16:18:19","guid":{"rendered":"https:\/\/lab.rapternet.us\/?p=2047"},"modified":"2023-02-12T17:02:24","modified_gmt":"2023-02-12T23:02:24","slug":"cleaning-up-the-docker-registry","status":"publish","type":"post","link":"https:\/\/lab.rapternet.us\/?p=2047","title":{"rendered":"Cleaning up the docker registry"},"content":{"rendered":"\n<p>Working on my docker swarm recently I noticed that my storage was running low. After investigation, I found I had 17GB of usage by my docker registry. I have no need to have that many versions of my custom built containers on hand, so I went through the process of cleaning it up.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>I started out by trying this, but it only marked 8 images for deletion.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">administrator@bot-docker-01:\/mnt\/administration\/Bash-Scripts\/Docker-Compose\/port-dev$ <strong>docker exec 355b5721ae5f \/bin\/registry garbage-collect \/etc\/docker\/registry\/config.yml<\/strong><\/pre>\n\n\n\n<p>After some additional research I managed to find out about this command. Running it netted me a few thousand images marked for deletion. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">administrator@bot-docker-01:\/mnt\/administration\/Bash-Scripts\/Docker-Compose\/port-dev$ <strong>docker exec -it -u root 355b5721ae5f bin\/registry garbage-collect --delete-untagged \/etc\/docker\/registry\/config.yml<\/strong><\/pre>\n\n\n\n<p>The container name is randomized from the swarm stack so that&#8217;s a bit odd. I used docker ps to get the name.<\/p>\n\n\n\n<p>With that command finally working to clear out the old versions, my container registry data usage dropped SIGNIFICANTLY. This is exactly what I was hoping for so that my gluster storage array would have a bit more free space.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resources<\/h2>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/45046752\/docker-registry-garbage-collection\">This stack overflow thread<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Contents Below:<\/h3>\n\n\n\n<p>Since Docker Registry 2.7.0 (current as of 2019-09-18 is 2.7.1) there is a flag <code>--delete-untagged<\/code> which removes those unreferenced blobs<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>docker exec -it -u root registry bin\/registry garbage-collect --delete-untagged \/etc\/docker\/registry\/config.yml<\/code><\/pre>\n\n\n\n<p>It doesn&#8217;t get rid of empty directories, though. All the empty blob and repository directories will still remain.<\/p>\n\n\n\n<p>I also couldn&#8217;t find any mention of that flag in the Docker Registry documentation, I found it in a GitHub thread.<\/p>\n\n\n\n<p>According to <a href=\"https:\/\/github.com\/docker\/distribution\/blob\/749f6afb4572201e3c37325d0ffedb6f32be8950\/registry\/root.go#L21\">the source code<\/a> the short form is <code>-m<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>GCCmd.Flags().BoolVarP(&amp;removeUntagged, \"delete-untagged\", \"m\", false, \"delete manifests that are not currently referenced via tag\")<\/code><\/pre>\n\n\n\n<p>Here is the pull request: <a href=\"https:\/\/github.com\/docker\/distribution\/pull\/2302\">https:\/\/github.com\/docker\/distribution\/pull\/2302<\/a><\/p>\n\n\n\n<p>EDIT: The <code>-m<\/code> (<code>--delete-untagged<\/code>) option is still buggy with multi-arch manifests: <a href=\"https:\/\/github.com\/distribution\/distribution\/issues\/3178\">https:\/\/github.com\/distribution\/distribution\/issues\/3178<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Future<\/h2>\n\n\n\n<p>Something that could be interesting to use in the future would be this:<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/ricardobranco777\/regview\/\">https:\/\/github.com\/ricardobranco777\/regview\/<\/a><\/p>\n\n\n\n<p>It may let me automate the whole cleanup process.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working on my docker swarm recently I noticed that my storage was running low. After investigation, I found I had 17GB of usage by my docker registry. I have no need to have that many versions of my custom built containers on hand, so I went through the process of cleaning it up.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[13,14,22],"class_list":["post-2047","post","type-post","status-publish","format-standard","hentry","category-how-to","tag-docker","tag-quick-bites","tag-services"],"_links":{"self":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts\/2047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2047"}],"version-history":[{"count":7,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts\/2047\/revisions"}],"predecessor-version":[{"id":2333,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=\/wp\/v2\/posts\/2047\/revisions\/2333"}],"wp:attachment":[{"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lab.rapternet.us\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}