<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://www.baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2017:11:27</title>
        <description></description>
        <link>https://www.baszerr.eu/</link>
        <lastBuildDate>Wed, 06 May 2026 09:38:05 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://www.baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://www.baszerr.eu/</link>
        </image>
        <item>
            <title>2017-11-27_-_cleaning_up_docker-registry</title>
            <link>https://www.baszerr.eu/doku.php?id=blog:2017:11:27:2017-11-27_-_cleaning_up_docker-registry</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;cleaning_up_docker-registry&quot;&gt;2017-11-27 - cleaning up docker-registry&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;https://www.baszerr.eu/lib/exe/detail.php?id=blog%3A2017%3A11%3A27%3A2017-11-27_-_cleaning_up_docker-registry&amp;amp;media=blog:2017:11:27:docker_registry.png&quot; class=&quot;media&quot; title=&quot;blog:2017:11:27:docker_registry.png&quot;&gt;&lt;img src=&quot;https://www.baszerr.eu/lib/exe/fetch.php?w=300&amp;amp;tok=9bf0db&amp;amp;media=blog:2017:11:27:docker_registry.png&quot; class=&quot;mediaright&quot; align=&quot;right&quot; loading=&quot;lazy&quot; title=&quot;docker registry logo&quot; alt=&quot;docker registry logo&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
it has been 2 months since last post and over 5 months since anything more verbose. &lt;a href=&quot;https://www.codedive.pl&quot; class=&quot;urlextern&quot; title=&quot;https://www.codedive.pl&quot; rel=&quot;ugc nofollow&quot;&gt;Code::Dive&lt;/a&gt; is now over and looks like i&amp;#039;ll have a bit of time to catch up blogging some ideas and implementations i&amp;#039;ve being doing around, but had no time to post about. today we&amp;#039;ll start with… &lt;a href=&quot;https://hub.docker.com/_/registry/&quot; class=&quot;urlextern&quot; title=&quot;https://hub.docker.com/_/registry/&quot; rel=&quot;ugc nofollow&quot;&gt;docker-registry&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
when setting up a new service, one must typically accept a bit of maintenance as well. :) there are 3 things you need to cover on your own, that might not come very obvious, if you have not set up a docker-registry instance before, namely:
&lt;/p&gt;
&lt;ol&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; HTTPS access&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; authentication/authorization&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; removal of (old?) images&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
first one is simple – just put &lt;a href=&quot;https://en.wikipedia.org/wiki/nginx&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/nginx&quot;&gt;nginx&lt;/a&gt; as a reverse-proxy, to terminate HTTPS, and use HTTP internally to contact to the instance.
&lt;/p&gt;

&lt;p&gt;
second one is not very complex either - for many cases it should be enough to configure the very same nginx instance you&amp;#039;re using for HTTPS, to enforce basic-auth on each and every path to reverse-proxied service.
&lt;/p&gt;

&lt;p&gt;
the third thing however is FAR from obvious. more over there is very little help on the internet. some ppl write a lot of voodoo scripts, that manipulate registry&amp;#039;s internals – this is definitely not a thing i wanted to have on my instance. it turns out that registry&amp;#039;s 2.0 version of &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; defined a &lt;a href=&quot;https://en.wikipedia.org/wiki/REST&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/REST&quot;&gt;REST&lt;/a&gt; call to untag images, BUT it was not stated clearly how to do this! more over only the most recent versions on registry (since 2.5 i think) actually have this call implemented.
&lt;/p&gt;

&lt;p&gt;
but how to use it? i&amp;#039;ve spent way more time i&amp;#039;d like to admit, to solve this issue. if you hit this page with the same problem – how to remove an image from a private registry, here&amp;#039;s the procedure.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;2017-11-27 - cleaning up docker-registry&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;cleaning_up_docker-registry&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-1854&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;configuration&quot;&gt;configuration&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
first thing, that is very easy to miss, is configuration. by default docker-registry does NOT allow any explicit removals! even if you set up everything else correctly, w/o this option the feature will just not work. what you need to do is edit &lt;code&gt;/etc/docker/registry/config.yml&lt;/code&gt; file and add the following section:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;storage:
  delete:
    enabled: true&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;configuration&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;configuration&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;1855-2252&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;remove_request&quot;&gt;remove request&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
the &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; looks very simple – just send a &lt;code&gt;DELETE&lt;/code&gt; request to &lt;code&gt;&lt;a href=&quot;http://myregistry:5000/v2/&quot; class=&quot;urlextern&quot; title=&quot;http://myregistry:5000/v2/&quot; rel=&quot;ugc nofollow&quot;&gt;http://myregistry:5000/v2/&lt;/a&gt;&amp;lt;image&amp;gt;/manifest/&amp;lt;blob-id&amp;gt;&lt;/code&gt;. cool – now how do i get the &lt;em&gt;blob-id&lt;/em&gt; thing? while most &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; calls do accept either ID, or just a name… delete does not. id is the only way to go.
&lt;/p&gt;

&lt;p&gt;
in order to get the ID, the tricky part is that special header must be set in the &lt;code&gt;GET&lt;/code&gt; query, namely &lt;code&gt;Accept: application/vnd.docker.distribution.manifest.v2+json&lt;/code&gt;. if you won&amp;#039;t set it, you&amp;#039;ll get a lot of different pieces of information, aside from the single one you&amp;#039;re actually looking for. :/ to make things even funnier - the response also comes in a header form…
&lt;/p&gt;

&lt;p&gt;
so the example call via &lt;code&gt;curl&lt;/code&gt;, that gets the &lt;em&gt;blob-id&lt;/em&gt; for a given image and a tag pair, can look like this:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;curl -q -v \
  -H &amp;quot;Accept: application/vnd.docker.distribution.manifest.v2+json&amp;quot; \
  -X GET \
  http://myregistry:5000/v2/&amp;lt;image&amp;gt;/manifests/&amp;lt;tag&amp;gt; 2&amp;gt;&amp;amp;1 | grep Docker-Content-Digest | awk &amp;#039;{ print $3 }&amp;#039;&lt;/pre&gt;

&lt;p&gt;
the output will look similar to this: &lt;code&gt;sha256:40506065be119bfc51093a65bf0123147cd2af72c767168dafdcb2d131f72e4d&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
now that we finally have the &lt;em&gt;blob-id&lt;/em&gt;, we can delete it, from the registry:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;curl -v -X DELETE http://myregistry:5000/v2/&amp;lt;image&amp;gt;/manifests/sha256:40506065be119bfc51093a65bf0123147cd2af72c767168dafdcb2d131f72e4d&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;remove request&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;remove_request&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;2253-3609&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;remove_data&quot;&gt;remove data&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
if you made it this far, you&amp;#039;ll notice that while you no longer can &lt;code&gt;docker pull&lt;/code&gt; the removed image, your disk space usage have not decreased either! the procedure above only removes a tag of the image, but does not remove data blobs, to free disk space!
&lt;/p&gt;

&lt;p&gt;
to actually wipe the data from the disk, garbage collector must be called, inside the docker-registry image, with a configuration file as a parameter. the call looks like this:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;docker exec -it my-registry-container \
  registry garbage-collect /etc/docker/registry/config.yml&lt;/pre&gt;

&lt;p&gt;
…and wait. for bigger registry this can take some minutes to complete and will flood your screen with messages.
&lt;/p&gt;

&lt;p&gt;
when the command will exit, your cleanup has just finished.
&lt;/p&gt;

&lt;p&gt;
oh – and btw: don&amp;#039;t run this whole procedure in parallel with adding stuff to your registry. even though it only uses the official &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; and provided commands, it still tends to leave registry in an inconsistent state! :/
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;remove data&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;remove_data&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;3610-4584&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit5&quot; id=&quot;aftermath&quot;&gt;aftermath&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
despite the procedure being from hell, pretty much undocumented (well – there is a documentation for all of it, but left on your own it is anything but trivial to glue the above procedure up!) and problematic in terms of stability, it is not the end of the story.
&lt;/p&gt;

&lt;p&gt;
when you use registry to store CI-build microservices images (which seems very natural), it is very common to have cleanup procedure of old images. explicit deleting some images is only a one step of a bigger run in there. of course getting list of images ordered by creation time is tricky as well, since tags do not have a creation date – only images have it. and all of the sudden automation of the cleanup becomes even bigger pain.
&lt;/p&gt;

&lt;p&gt;
long story short – as of writing this post, the procedure is terrible and barely usable. it think there is huge opportunity for improvements here and i hope we&amp;#039;ll see better &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; in the future. in particular it would be nice to have a registry-operating &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; embedded directly into &lt;code&gt;docker&lt;/code&gt; client application. &lt;code&gt;push&lt;/code&gt; and &lt;code&gt;pull&lt;/code&gt; are there, but removal is unfortunately still missing.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;aftermath&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;aftermath&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;4585-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:09:47 +0000</pubDate>
        </item>
        <item>
            <title>2017-11-27_-_strings_and_sso</title>
            <link>https://www.baszerr.eu/doku.php?id=blog:2017:11:27:2017-11-27_-_strings_and_sso</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;strings_and_sso&quot;&gt;2017-11-27 - strings and SSO&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
since many years &lt;a href=&quot;https://en.wikipedia.org/wiki/C++&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/C++&quot;&gt;C++&lt;/a&gt; standard not only prohibits copy-on-write (aka: CoW) strings implementation, but even allows implementations to use small-string-optimization (aka: SSO). i&amp;#039;ve recently came across an interesting bug, “using” this corner case, in a code similar to this:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;std::string value_;
// ...
std::string one{&amp;quot;foo&amp;quot;};
char const* ptr = one.data(); // 1
std::string two{ std::move(one) };
// ... &amp;#039;one&amp;#039; no longer exists here ...
// ... &amp;#039;two&amp;#039; is still here ... 
cout &amp;lt;&amp;lt; ptr; // valid or not?&lt;/pre&gt;

&lt;p&gt;
it used to work on one of the compilers, but not on the other.
&lt;/p&gt;

&lt;p&gt;
it turned out that one of the implementations used SSO, while other did not. when there was no SSO, line (1) was ok, since &lt;code&gt;one.data()&lt;/code&gt; returned the very same, heap-allocated pointer, that later on was passed for ownership to the string &lt;code&gt;two&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
however when SSO kicks in, short sting may be kept on stack! no memory allocation is performed, but also &lt;code&gt;one.data()&lt;/code&gt; will never be equal to &lt;code&gt;two.data()&lt;/code&gt;, regardless if &lt;code&gt;two&lt;/code&gt; is copy- or move- initialized. the net effect is dangling pointer and UB is unleashed.
&lt;/p&gt;

&lt;p&gt;
so is the code correct or not? NO – it is NOT correct! why? because SSO is valid, standard-compliant implementation feature of &lt;code&gt;std::string&lt;/code&gt; and one may not rely on it being (or not being) there. even if your compiler does not implement it yet, it might still break badly with next compiler update. and to make things worse, it will break silently.
&lt;/p&gt;

&lt;p&gt;
lesson learned is that one should never assume neither any particular state of moved-from object, nor a state of pointer/reference generated out of it, unless this is explicitly stated inside the library. one famous example of such special case are &lt;code&gt;std::shared_ptr&lt;/code&gt; and &lt;code&gt;std::unique_ptr&lt;/code&gt; that, when moved from, guarantee to be &lt;code&gt;nullptr&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
by default however, there are no guarantees for other objects. technically speaking moved-from object must only be able to safely destroy itself (i.e. call d-tor). nothing more.
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:09:47 +0000</pubDate>
        </item>
    </channel>
</rss>
