<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by beld 🎩 on Medium]]></title>
        <description><![CDATA[Stories by beld 🎩 on Medium]]></description>
        <link>https://medium.com/@beld_pro?source=rss-d33bc357db------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iXXPfRz6WkJecQ9Ib3L99Q.jpeg</url>
            <title>Stories by beld 🎩 on Medium</title>
            <link>https://medium.com/@beld_pro?source=rss-d33bc357db------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:36:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@beld_pro/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Inspecting Docker images without pulling them]]></title>
            <link>https://medium.com/hackernoon/inspecting-docker-images-without-pulling-them-4de53d34a604?source=rss-d33bc357db------2</link>
            <guid isPermaLink="false">https://medium.com/p/4de53d34a604</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[beld ]]></dc:creator>
            <pubDate>Sun, 26 Nov 2017 00:00:00 GMT</pubDate>
            <atom:updated>2017-11-27T20:34:52.091Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TjivBbS5QyKZO0wBKxg9QA.jpeg" /></figure><p>Hey,</p><p>depending on what you’re trying to build it might happen that part of it involves inspecting a Docker image from a registry but you can’t afford to pull it.</p><p>It turns out that <a href="https://docs.docker.com/registry/spec/api/">there’s an API</a> that allows you to perform exactly that — be it DockerHub or a private registry.</p><blockquote><em>The Docker Registry HTTP API is the protocol to facilitate distribution of images to the docker engine. It interacts with instances of the docker registry, which is a service to manage information about docker images and enable their distribution.</em></blockquote><h3>Testing it locally</h3><p>The first step to test it locally is raising a registry from the <a href="https://hub.docker.com/_/registry/">library/registry</a> image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fa81449fe7b1522ae5daab983fee242/href">https://medium.com/media/6fa81449fe7b1522ae5daab983fee242/href</a></iframe><p>Check that it’s definitely working:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f094dc5e657df1de801a16fefd385a3/href">https://medium.com/media/8f094dc5e657df1de801a16fefd385a3/href</a></iframe><p>Having the local registry working, we can move to the script that inspects images right from the registry metadata. The following script contains all that it takes to retrieve it and relies only on two dependencies: bash and <a href="https://stedolan.github.io/jq/">jq</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e2fcba00bb26c89bd931dbccb999f2b/href">https://medium.com/media/2e2fcba00bb26c89bd931dbccb999f2b/href</a></iframe><p><em>ps.: It’s important to note that the API calls need to specify the type of content that it accepts (</em><em>application/vnd.docker.distribution.manifest.v2+json).</em></p><p>Let’s now check if it’s working for real:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06d7ef36112ba74dd526edaeb5d5e1b2/href">https://medium.com/media/06d7ef36112ba74dd526edaeb5d5e1b2/href</a></iframe><p>Cool, it indeed works!</p><p>While that does the job for registries that require no authentication, it’s not suitable for DockerHub. When checking a public image there, we need to perform an extra step before getting the digest of an image — retrieve a token. With such token in hand, we can then inspect either public or private images.</p><p>Going back to scripting, let’s create a different one to deal with this case — call it get-public-image-config.sh (this is for brevity sake, using some other programming language you could place some conditionals and detect each case).</p><p>The additional code can be placed in a method called get_token which only takes image as an argument:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/356ce0838c00a24cad434dc34fc80880/href">https://medium.com/media/356ce0838c00a24cad434dc34fc80880/href</a></iframe><p>With the token in hands it’s just a matter of making use of it on the other calls.</p><p>If we were targetting private images we’d modify get_token a little bit: on the call to get the token from auth.docker.io we’d need to do it with a DockerHub username and password pair (without authentication we can only have access to public images). To do so, specify in that call an authorization header (--user flag in curl):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74e8ae1af6437cfdd62e08b1cc879f76/href">https://medium.com/media/74e8ae1af6437cfdd62e08b1cc879f76/href</a></iframe><p>Now with this new token we can retrieve the digest of a given image and tag (pay attention to the extra Authorization: Bearer $token header that we added):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/993487928de4470a7e3f8a8bd26cfcac/href">https://medium.com/media/993487928de4470a7e3f8a8bd26cfcac/href</a></iframe><p>With that we can have a full script that retrieves public images from DockerHub (check how in main we first retrieve a token, then we pass that token to the following methods):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2744a5c36df784213506b0633ecad256/href">https://medium.com/media/2744a5c36df784213506b0633ecad256/href</a></iframe><p><em>Note.: again, you must add the full name of the image (official images use the </em><em>library repository so </em><em>nginx should be referred as </em><em>library/nginx).</em></p><p>To make sure that it works, run it against an image like <a href="http://hub.docker.com/_/nginx">nginx</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05e2256242d86f7bf26140e8a1d47358/href">https://medium.com/media/05e2256242d86f7bf26140e8a1d47358/href</a></iframe><p>If you try to retrieve an image that is not very new (say, that has some 2 years) you’ll notice that the script I posted above might not work.</p><p>The reason for that is that images that have been pushed to the docker registry a long time ago won’t use the second version of the V2 manifest. However, they still present the image configuration even though in a regular string.</p><p>Bellow is a script that deals with that case:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a203418326985b2e9814c09c52fc6f5/href">https://medium.com/media/4a203418326985b2e9814c09c52fc6f5/href</a></iframe><p>If you’re looking for the difference, look at main. Essentially we abandon the idea of retrieving a digest and simply pick the “old config”. From the old config, we look at the first blob in the list which represents the uppermost layer - the layer that contains all the info altogether. From there we parse that plain-text JSON and then get the config.</p><h3>Closing thoughts</h3><p>Interacting with DockerHub or a private registry is not all that hard, it’s just not very documented. Having these scripts it becomes pretty easy to get it working on any language you want — just add some checks, parse the image names and you should be good to go.</p><p>Here are the resources mentioned in the article:</p><ul><li><a href="https://docs.docker.com/registry/spec/api/#content-digests">Docker Registry API — Content Digests</a></li><li><a href="https://docs.docker.com/registry/spec/api/#pulling-an-image-manifest">Docker Registry API — Pulling an Image Manifest</a></li><li><a href="https://docs.docker.com/registry/spec/api/#pulling-a-layer">Docker Registry API — Pulling a Layer</a></li><li><a href="https://gist.github.com/cirocosta/17ea17be7ac11594cb0f290b0a3ac0d1">Gist: all the scripts mentioned here</a></li></ul><p>I can&#39;t finish the article without mentioning some alternatives that people suggested after I first published the article in <a href="https://ops.tips/blog/inspecting-docker-image-without-pull/">ops.tips</a>:</p><ul><li><a href="https://github.com/GoogleCloudPlatform/container-diff">https://github.com/GoogleCloudPlatform/container-diff</a> — <em>&quot;Diff your Docker containers&quot;</em> — it looks pretty interesting but even though you can specify remote:// to an image when analyzing it, it looks like it always pulls the entire image. Maybe I got something wrong?</li><li><a href="https://github.com/projectatomic/skopeo">https://github.com/projectatomic/skopeo</a> — <em>”Work with remote images registries — retrieving information, images, signing content”</em> — well, does exactly what it says! I totally recommend for the purpose of inspecting images or repositories without pulling them 👍</li></ul><p>By the way, if you wan’t to try Skopeo, building it from source is very easy on MacOS:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98a252c3e78587d57e35546d70c492a2/href">https://medium.com/media/98a252c3e78587d57e35546d70c492a2/href</a></iframe><p>Now inspecting an image or a repository from Dockerhub is one command away:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b85f533bd8476b513baf7d44fb94c73e/href">https://medium.com/media/b85f533bd8476b513baf7d44fb94c73e/href</a></iframe><p>Note that here I’m specifying the --override-os flag to the command. The reason is that otherwise it’ll try to inspect the image or repository filtering by digests marked with OS=darwin. If you’re using Linux you’d not need to use that flag.</p><p>If you’re not willing to implement in your favorite language and just want to gather the configuration of an image, make sure you check Skopeo.</p><p>Please let me know if I got anything wrong and/or if there’s an easier way to do it.</p><p>Have a good one!</p><p><em>finis</em></p><p><em>Originally published at </em><a href="https://ops.tips/blog/inspecting-docker-image-without-pull/"><em>ops.tips</em></a><em> on November 26, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4de53d34a604" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/inspecting-docker-images-without-pulling-them-4de53d34a604">Inspecting Docker images without pulling them</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Changing the name of an index in Elasticsearch]]></title>
            <link>https://medium.com/hackernoon/changing-the-name-of-an-index-in-elasticsearch-28487b517ad1?source=rss-d33bc357db------2</link>
            <guid isPermaLink="false">https://medium.com/p/28487b517ad1</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[beld ]]></dc:creator>
            <pubDate>Tue, 21 Nov 2017 00:00:00 GMT</pubDate>
            <atom:updated>2017-11-26T21:00:22.971Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Nu1_YBJ5AZhhwRR5dNsyA.jpeg" /></figure><p>Hey,</p><p>today I happened to write a script to solve a specific problem that it looks like a good deal of people face: renaming a given Elasticsearch index. Naturally, there are documented solutions but I didn’t find quickly a script that would get me where I wanted — all the data from an index named a now being queryable in an index named b with all the properties set.</p><p><em>Note.: the following code is aimed at Elasticsearch 2.4.6.</em></p><p>Here it comes then.</p><h3>Reindexing step by step</h3><p>There are four steps to get towards our goal:</p><ol><li>Create an Elasticsearch index and populate it with some data;</li><li>Get the configurations of the original index;</li><li>Create the new index with the desired configuration;</li><li>Run _reindex action;</li><li>Drop the old index.</li></ol><h4>0. Create an Elasticsearch index and populate it with some data</h4><p>To create an index using the default parameters (e.g, number of shards and replicas) we can issue a POST against the Elasticsearch HTTP endpoint specifying the desired index (in this case, acme-production:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f806eed8f0a38be263861368823bed3a/href">https://medium.com/media/f806eed8f0a38be263861368823bed3a/href</a></iframe><p>Which, naturally, has no data indexed:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f792b89e6dc5f0c7492a9e3cd1817fba/href">https://medium.com/media/f792b89e6dc5f0c7492a9e3cd1817fba/href</a></iframe><p>Now we populate it with some data:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9342c7fbe38ec34bab6bfe67f9cc2a71/href">https://medium.com/media/9342c7fbe38ec34bab6bfe67f9cc2a71/href</a></iframe><p>Which we can verify by looking again at the /_cat/indices endpoint:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/878c678d714eba0a0d6f0d7be309fdae/href">https://medium.com/media/878c678d714eba0a0d6f0d7be309fdae/href</a></iframe><h4>1. Get the configurations of the original index</h4><p>Because the renaming is nothing more than “create, copy and delete” we need to create a new index with the properties from the old one. To properly achieve that we must then copy the old configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03c1058ede825224a6da8dc9970cfec4/href">https://medium.com/media/03c1058ede825224a6da8dc9970cfec4/href</a></iframe><p>ps.: here I’m making use of <a href="https://stedolan.github.io/jq/">jq</a>, the lightweight command-line JSON processor, in order to get the mappings and settings objects from within the bigger object returned by the call to /&lt;index&gt;/_settings,_mappings. This way we’re able to assign that to a variable and then make use of it later.</p><h4>2. Create the new index with the desired configuration</h4><p>Using the old configuration (stored in the index_config variable) we’re able to create the the index based on it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82f865e646ae3b2906724599490b4a94/href">https://medium.com/media/82f865e646ae3b2906724599490b4a94/href</a></iframe><p><em>ps.: even though there’s an </em><em>uuid in the </em><em>$index_config object there, it doesn’t matter - it’ll get replaced by a new </em><em>uuid in the new index.</em></p><h4>3. Run _reindex action</h4><p>Having both indices properly configured we’re ready to have the data from the old index in the new one:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38774ba98a20fcc3d590604acebf3079/href">https://medium.com/media/38774ba98a20fcc3d590604acebf3079/href</a></iframe><p>By this time you should already have your new index populated. Now it’s a matter of deleting the old index:</p><h4>4. Drop the old index</h4><p>If you have no intention of making use of the old index, now it’s time to drop it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94992b4bad27e0677edb0b495279df57/href">https://medium.com/media/94992b4bad27e0677edb0b495279df57/href</a></iframe><h4>What about aliases?</h4><p>I received some pretty interesting feedback on Reddit that I’d like to share here.</p><p>It turns out that sometimes we can avoid reindexing by making use of aliases (see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html">Elasticsearch Indices Aliases</a>).</p><p>The idea is that when we need to reference what’s covered by an index by using another name we can create some kind of “pointer” to the real index and perform all the normal operations against this pointer (alias). The API that allows doing that allows us to essentially CRUD (create, remove, update and delete) aliases, making it totally possible for us to perform what we want: achieve a “renaming” of an index, even if only virtually.</p><p>Let’s do it then.</p><p>First, create an acme-production index just like before and add some data:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe27cdac48ac587719306174abf6a06e/href">https://medium.com/media/fe27cdac48ac587719306174abf6a06e/href</a></iframe><p>then create an alias named acme-staging:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86f6d2c36653ed38b81a3f0b5e7715f3/href">https://medium.com/media/86f6d2c36653ed38b81a3f0b5e7715f3/href</a></iframe><p>if we check the indices we’ll see that we don’t have any new index though:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fe1deffa42f42a3623adc84faf548dd/href">https://medium.com/media/0fe1deffa42f42a3623adc84faf548dd/href</a></iframe><p>But that we do have aliases:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e862b1f030576c8c73c431d1a84c6a3/href">https://medium.com/media/6e862b1f030576c8c73c431d1a84c6a3/href</a></iframe><p>which allows us to perform queries against acme-staging and retrieve data from acme-production:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82ce12165e1ae3f69ccfb89a997314b8/href">https://medium.com/media/82ce12165e1ae3f69ccfb89a997314b8/href</a></iframe><p>Now, what if we want to disallow requests to the old index? As if we had really renamed it and not duplicated? Then we need to close the old index using the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-open-close.html">open/close index api</a>:</p><pre>curl -XPOST <a href="http://localhost:9200/acme-production/_close">http://localhost:9200/acme-production/_close</a></pre><p>then we can try to get from acme-production:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00f5e92f991b91a0e6b2f59683139581/href">https://medium.com/media/00f5e92f991b91a0e6b2f59683139581/href</a></iframe><p>Cool, what we wanted, huh? Now, if we try to get from acme-staging:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c86efd58bed8f3c568dbfbb7c8dba9d6/href">https://medium.com/media/c86efd58bed8f3c568dbfbb7c8dba9d6/href</a></iframe><p>we can’t retrieve either.</p><p>It sounds logical to me that we can’t as the alias is just a pointer to the other index (which was closed).</p><p>So, to sum up, if you want to have new indices to point to an existing one (as if you were renaming), aliases will save you and you’ll need to perform 0 copying of data.</p><p>If you need to have something like “rename” and disallow access to the old index, then alias won’t help you (will have to use the reindex + delete strategy.</p><p>I never used aliases before and it’s pretty good to know that they exist! It can definitely be very useful some times.</p><h3>Closing thoughts and resources</h3><p>As someone who never really dug deep into how Elasticsearch works, I found very easy the whole concept of reindexing. The official documentation is pretty good and with it, I was able to quickly solve the problem. Kudos Elasticsearch team!</p><p>Thanks,</p><p><em>finis</em></p><p><em>Originally published at </em><a href="https://ops.tips/blog/change-name-of-index-elasticsearch/"><em>ops.tips</em></a><em> on November 21, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28487b517ad1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/changing-the-name-of-an-index-in-elasticsearch-28487b517ad1">Changing the name of an index in Elasticsearch</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How does Docker play with Cgroups when I create an instance?]]></title>
            <link>https://medium.com/@beld_pro/how-does-docker-play-with-cgroups-when-i-create-an-instance-6ce24daccfb2?source=rss-d33bc357db------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ce24daccfb2</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[beld ]]></dc:creator>
            <pubDate>Tue, 11 Jul 2017 00:07:31 GMT</pubDate>
            <atom:updated>2017-07-11T00:08:55.061Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mbu5-mfb_mvbYu10fs8FpQ.jpeg" /></figure><p>Wondering about how Docker was using the --pids-limit property made me understand a little bit about how CGroups work. Come with me to find out more about it 👍</p><p>If you run a recent version of Docker (in my case I&#39;m on 17.06.0-ce ) you can verify that docker run has a --pids-limits option that is meant to limit the number of processes that a process can create. From the <a href="https://www.kernel.org/doc/Documentation/cgroup-v1/pids.txt">Kernel documentation</a>:</p><blockquote>The process number controller is used to allow a cgroup hierarchy to stop any<br>new tasks from being fork()&#39;d or clone()&#39;d after a certain limit is reached.<br><br>Since it is trivial to hit the task limit without hitting any kmemcg limits in<br>place, PIDs are a fundamental resource. As such, PID exhaustion must be<br>preventable in the scope of a cgroup hierarchy by allowing resource limiting of<br>the number of tasks in a cgroup.</blockquote><p>In order words: <em>worried about what an explosion in the number of PIDs can cause to your system? Place the process under this control group and you should be fine</em>.</p><p>So, let&#39;s see it in practice!</p><ol><li>create a container without PID limits and see where it goes in terms of number of PIDs:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/943361cddddd2bcab5cee9492c64dea8/href">https://medium.com/media/943361cddddd2bcab5cee9492c64dea8/href</a></iframe><p>2. Verify that Docker placed some cgroups for this container:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad63a2f834b003ad7cc98fdb83749e56/href">https://medium.com/media/ad63a2f834b003ad7cc98fdb83749e56/href</a></iframe><p>That&#39;s cool. Now, how would that change with some constraint like --pids-limit ? Let&#39;s see:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/577db70f91d5adf94bd4ef74c3869bf7/href">https://medium.com/media/577db70f91d5adf94bd4ef74c3869bf7/href</a></iframe><p>Does that really work? Sure!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0da6d1bd2c23a8258edf245cb37d8aa/href">https://medium.com/media/d0da6d1bd2c23a8258edf245cb37d8aa/href</a></iframe><p>That&#39;s it!</p><p>Where to go next? The Docker daemon presents us the ability to configure a parent cgroup that all containers launched by such daemon will inherit from (see <a href="https://docs.docker.com/engine/reference/commandline/dockerd/#default-cgroup-parent">https://docs.docker.com/engine/reference/commandline/dockerd/#default-cgroup-parent</a>). That&#39;s something also present in commands like docker build which run containers but don&#39;t present much runtime constraints configuration. With the ability to create a CGroup and have docker use it we can then improve resource limiting 🙌</p><p>Hey, if I said something wrong here (or if you have any tips 👌), just let me know! For more on these, follow me at Twitter — <a href="https://twitter.com/beld_pro">twitter.com/beld_pro</a> 🎩</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ce24daccfb2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Where does Cloudstor puts the files from my volumes when I use Docker for AWS?]]></title>
            <link>https://medium.com/hackernoon/where-does-cloudstor-puts-the-files-from-my-volumes-when-i-use-docker-for-aws-da63fa53567d?source=rss-d33bc357db------2</link>
            <guid isPermaLink="false">https://medium.com/p/da63fa53567d</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[beld ]]></dc:creator>
            <pubDate>Sun, 25 Jun 2017 18:24:09 GMT</pubDate>
            <atom:updated>2017-07-20T19:23:08.546Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ot_UEUXdNXSQQ6ZAjSxtTg.png" /></figure><p>Hey, another quick tip regarding Docker, specially the <a href="https://docs.docker.com/docker-for-aws/">Docker for AWS</a> offering (edge edition) which ships with cloudstor . That&#39;s a volume plugin that does enables containers to attach volumes that are saved into <a href="https://aws.amazon.com/efs/">AWS EFS</a> allowing one to benefit from both shared storage as well as durable storage (think of network filesystem that is backed by AWS and wrapped on a nice interface by Docker).</p><p>Here I go through how you can visualize how the plugin puts stuff into EFS.</p><p><strong>tl;dr</strong>: <strong>the plugin runs inside a container with a mount point with mounts to EFS where for each named volume it creates a directory (which gets propagated over the machines).</strong></p><p><em>Note.: I&#39;m not from Docker and neither have all the informations about how things work there. Some of these things are proprietary and are not very much documented but we can still have an idea about how things work. Feel free to correct me in case I get something wrong. </em>😁</p><p>First things first, if you&#39;ve already set up docker-for-aws once (using their standard <a href="https://aws.amazon.com/cloudformation">CloudFormation</a> template) you probably noticed that you don&#39;t really log into the machine, but into a container with SSH that is running on the host. This is one of the set of containers that are kept running there to interact with AWS and make the whole thing cohesive.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d630ab7abfd7a9dea576bc3b93f6c13b/href">https://medium.com/media/d630ab7abfd7a9dea576bc3b93f6c13b/href</a></iframe><p>There&#39;s one container that is missing, though: the cloudstor:aws . That&#39;s because plugins like cloudstor:aws (the volumes plugin mentioned above) runs inside containers (see <a href="https://docs.docker.com/engine/extend/plugin_api/#what-plugins-are">https://docs.docker.com/engine/extend/plugin_api</a>) and react to command issued against the docker daemon in a given host. So, now the question: where is that container? How can I see it?</p><p>To do that we must get out of the &quot;jail&quot; placed by the SSH container that we get in when SSHing. We can do that, guess what, with a container:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d11c477965d6bbc127c5646c56560e3d/href">https://medium.com/media/d11c477965d6bbc127c5646c56560e3d/href</a></iframe><p>What the command above does is allow us to have a container with all privileges grant, sharing the PID namespace of the host (thus we have access to the host&#39;s processes) and then using the imagejustincormack/nsenter1 which essentially gives us a way of entering the mount namespace of the PID 1 of the host (thus, giving us access to all the files of the host).</p><p>(see <a href="https://github.com/justincormack/nsenter1/blob/01ad645aacbf23d8967f671d8ec6af3046ae5e6f/nsenter1.c">nsenter1.c</a> to get into what nsenter1 does)</p><p>Once you&#39;re there (in the whole view of the host files) we have access to docker-runc (see <a href="https://runc.io/">runc.io</a>), which essentially is the most low-level engine that docker uses to create and run linux containers. Just execute docker-runc list :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d8ffadd17d06220089495edfb29d4e1/href">https://medium.com/media/6d8ffadd17d06220089495edfb29d4e1/href</a></iframe><p>Those bundle directories gives us the place where we can find the config.json files used by runc to create the containers. Whenever we want to exec into one of those containers, we can use docker-runc exec -t &lt;cid&gt; /my/binary . Interesting but still not there.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/979637673f0f2e6fcd18aca83fc4dab7/href">https://medium.com/media/979637673f0f2e6fcd18aca83fc4dab7/href</a></iframe><p>We&#39;re interested in the container that is run by the docker volume plugin so we must first get the id of the container. To do so, issue docker plugin ls --notrunc , which will give us in the ID section the full id of the containers. Now we can use the ID to get to the directory where we can find the configuration of the container running the plugin.</p><p>The configuration file (`config.json`) describes all the bare minimum set of properties needed for a linux container to be run (you can check out about it at <a href="https://github.com/opencontainers/runc">https://github.com/opencontainers/runc</a>). It&#39;s interesting but doesn&#39;t describe much about the plugin, as that&#39;s too low level.</p><p>Using the plugin API (docker plugin inspect &lt;pluginID&gt; ) we can find something useful: there&#39;s something being mount to /mnt as, <a href="https://github.com/moby/moby/pull/26398">https://github.com/moby/moby/pull/26398</a> states that &quot;Volume plugins that do mounts and want it to propagate to the host namespace, need to mount inside /mnt.&quot;, so, let&#39;s look at what&#39;s under that /mnt :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e90041f2f0e774a594226872d41ca12f/href">https://medium.com/media/e90041f2f0e774a594226872d41ca12f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc4c1f8bd6e6a5f362eeb939ed0b5828/href">https://medium.com/media/dc4c1f8bd6e6a5f362eeb939ed0b5828/href</a></iframe><p>So there it is! The named volumes we create end up under directories in a /mnt directory inside the plugin containers that run in our hosts. As they all have this /mnt on EFS, then we have the storage shared on all these machines. Pretty neat 🕺🏻</p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da63fa53567d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/where-does-cloudstor-puts-the-files-from-my-volumes-when-i-use-docker-for-aws-da63fa53567d">Where does Cloudstor puts the files from my volumes when I use Docker for AWS?</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick Tip: Installing OpenJDK in Debian container]]></title>
            <link>https://medium.com/hackernoon/install-java-in-docker-container-1d361e2e027e?source=rss-d33bc357db------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d361e2e027e</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[beld ]]></dc:creator>
            <pubDate>Tue, 16 May 2017 14:12:49 GMT</pubDate>
            <atom:updated>2017-07-19T15:36:15.477Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mBK1v7z7zWvKTcKxyRL2Mg.png" /></figure><p>The default Debian sources doesn&#39;t include the latest OpenJDK but you can get it from jessie-backports . Here&#39;s a quick tip to install it in a container.</p><p>First of all, get debian:jessie into your Docker daemon:</p><pre>docker pull debian:jessie</pre><pre>jessie: Pulling from library/debian</pre><pre>10a267c67f42: Pull complete</pre><pre>Digest: sha256:476959...c758245937</pre><pre>Status: Downloaded newer image for debian:jessie</pre><p>Now run a container that uses debian:jessie and and add jessie-backports sources to our sources:</p><pre>docker run -it debian:jessie /bin/bash</pre><pre>...</pre><pre>echo &#39;deb <a href="http://deb.debian.org/debian">http://deb.debian.org/debian</a> jessie-backports main&#39; \<br>      &gt; /etc/apt/sources.list.d/jessie-backports.list</pre><p>That is, insert deb <a href="http://deb/">http://deb</a> ... to the file /etc/apt/sources.list.d/jessie-backports.list . deb indicates that the archive contains binary .deb packages and where these can be found (here you could either specify the official debian.org or another <a href="https://www.debian.org/mirror/list">mirror</a>). Right after the URL we specify a distribution, which can be thought of as a release to target at. Here we target jessie-backports which contains more cutting-edge releases (see <a href="https://backports.debian.org/Instructions/">https://backports.debian.org/Instructions/</a>).</p><p>Having that done, update your package lists with apt update . What this does is essentially fetch information about the version of packages that can be fetched (it won&#39;t upgrade the packages you have installed though).</p><pre>apt update -y</pre><pre>Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]</pre><pre>...</pre><pre>Get:3 http://deb.debian.org jessie-backports InRelease [166 kB]</pre><pre>...</pre><pre>All packages are up to date.</pre><p>Now it&#39;s just a matter of targeting thejessie-backports distribution and installing openjdk8 👌</p><pre>apt install --target-release jessie-backports \<br>      openjdk-8-jre-headless \<br>      ca-certificates-java \<br>      --assume-yes</pre><p>Notice the use of --target-release . This allows us to target packages from jessie-backports (there&#39;s where openjdk8-jre-headless is present). With --assume-yes we are not prompted for confirmations).</p><p>And that&#39;s it! Now you have the latest OpenJDK installed 👊</p><pre>java -version</pre><pre>openjdk version &quot;1.8.0_131&quot;</pre><pre>OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-1~bpo8+1-b11)</pre><pre>OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)</pre><p>Below is a Dockerfile that installs OpenJDK following what was discussed here. You can build it using docker build --tag &lt;image_name&gt; . (where . indicates the directory where you put the Dockerfile).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9fb1ea18ed39966ca51092826bc70a4/href">https://medium.com/media/c9fb1ea18ed39966ca51092826bc70a4/href</a></iframe><p>And that&#39;s it!</p><p>If you have any questions, let me know!</p><p>Follow me on Twitter if you wish to get in touch and have some updates about this kind of things ✌️ <a href="https://twitter.com/beld_pro">twitter.com/beld_pro</a> .</p><p>🎩</p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d361e2e027e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/install-java-in-docker-container-1d361e2e027e">Quick Tip: Installing OpenJDK in Debian container</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing Postgres  with Golang]]></title>
            <link>https://medium.com/@beld_pro/postgres-with-golang-3b788d86f2ef?source=rss-d33bc357db------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b788d86f2ef</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[beld ]]></dc:creator>
            <pubDate>Sat, 13 May 2017 17:41:39 GMT</pubDate>
            <atom:updated>2017-05-13T17:44:46.023Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DpU1TvJtwqv2j-Bslvs7RQ.png" /></figure><h3>Managing Postgres with Golang</h3><p>Golang gives the developer a very consistent interface that can be used across SQL implementations. Some details are not super straightforward, though. Here I go through the basics of connecting to a SQL database, creating a table and listing its contents.</p><p>If you’re not very into pre-made ORM (Object Relational Mapping), here you can find a configuration that allows you to connect to a Postgres Database and write your own accessor/writer methods that reads from and insert into a table.</p><p>To have it started we use Go’s database/sql package. It is the base to provide us a generic interface around SQL — while not being specific to a SQL implementor. On top of that, we need a SQL driver — in this case, a Postgres driver. For Postgres, I recommend github.com/lib/pq .</p><p>Having that, let’s jump to the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9a07ae0dcec7f81bf41c8bec7620905/href">https://medium.com/media/f9a07ae0dcec7f81bf41c8bec7620905/href</a></iframe><p>First we start with the imports. Aside from dabatase/sql and github.com/lib/pq that we already mentioned, it&#39;s also included go-spew and pkg/errors .</p><p>The first gives us nice pretty printing of deep structures. Essentially it takes an object and creates a nice string representation of it (very useful for debugging purposes).</p><p>The second allows us to stack errors and add context to them.</p><p>Having both spew and pkg/errors combined allows us to get all the context we need in the case of a database connection error in our New() method — connection parameters and error generated by the native database/sql package.</p><p>We define Config as the struct to hold the parameters to the database connection. This allows us to make this package very generic and connect to any postgres instance we wish (disclaimer: i wrote this for interfacing with <a href="https://github.com/cockroachdb/cockroach">CockroachDB</a> — which exposes a Postgres interface — and not Postgres solely).</p><p>New() becomes then the holder of our pool of connections provided by database/sql . That is, whenever we want to interface with our Postgres instance we use Roach.Db which is then responsible for managing the connections.</p><p>It&#39;s important to note that sql.Open won&#39;t create a connection at the moment you call it (nor validate the parameters you passed to it), but only when you actually need it. As we&#39;re setting up the parameters we force a connection with db.Ping() .</p><p>Having no errors, we got our database set up for whatever we want 👌.</p><p>Now let&#39;s set up a sample table that uses Roach .</p><h4>Creating a table, inserting and fetching rows</h4><p>Bellow you can see how one can wrap the Roach struct implementing some methods that use the connection acquired by it to modify/insert content.</p><p>The code is highly commented so that you can grab each piece of it and use as you wish.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e1e80e46f41f290ddd3033c3122e250/href">https://medium.com/media/7e1e80e46f41f290ddd3033c3122e250/href</a></iframe><p>The code above tries to be very descriptive and really deal with some of the error handling that other posts miss.</p><p>Here are the three resources that I used to create this article / code:</p><ul><li><a href="http://go-database-sql.org/">http://go-database-sql.org/</a> (you should <strong>really </strong>check this out)</li><li><a href="https://golang.org/pkg/database/sql">https://golang.org/pkg/database/sql</a> good place to read the official database/sql nuances and eventually go through the code</li><li><a href="https://github.com/lib/pq">https://github.com/lib/pq</a> worth checking out if you wish to use the Postgres driver</li><li><a href="https://medium.com/@beld_pro/quick-tip-creating-a-postgresql-container-with-default-user-and-password-8bb2adb82342">https://medium.com/@beld_pro/quick-tip-creating-a-postgresql-container-with-default-user-and-password-8bb2adb82342</a> Go through the process of setting a simple PostgreSQL Docker container</li></ul><p>If you have any comments about this, please let me know! By the way, I&#39;m super open so feel free to reach me at <a href="https://twitter.com/beld_pro.">https://twitter.com/beld_pro</a> .</p><p>✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b788d86f2ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting User and Password from Basic Authorization headers with Nginx]]></title>
            <link>https://medium.com/@beld_pro/getting-user-and-password-from-basic-authorization-headers-with-nginx-c665d5522f1e?source=rss-d33bc357db------2</link>
            <guid isPermaLink="false">https://medium.com/p/c665d5522f1e</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[sysadmin]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[beld ]]></dc:creator>
            <pubDate>Tue, 09 May 2017 16:39:44 GMT</pubDate>
            <atom:updated>2017-05-09T16:39:44.352Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c5s79JqiE0GlekJuDWrkxg.jpeg" /></figure><p>With Lua support in NGINX, each request is inspectable and modifiable. To get the user and password we access the request headers and decode one in particular: the *Authorization: Basic* one. This article showcases how you can achieve that.</p><p><em>Resulting code at </em><a href="https://github.com/beldpro-ci/sample-basic-to-bearer-nginx"><em>https://github.com/beldpro-ci/sample-basic-to-bearer-nginx</em></a><em>.</em></p><p>A long time ago GitHub introduced a way of performing git operations against an authenticated endpoint by providing a token to the remote (<a href="https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth">https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth</a>). It’s pretty straightforward: add the token to the URL so that git performs basic authentication when connecting to GitHub servers.</p><p>The weird thing is that you’re using a Basic authorization for something that Bearer is suited for. Now, if we were GitHub and didn’t want to mess the semantics of out authentication code with a different rule, we could have our Nginx server (that could be acting as a reverse proxy) to do that.</p><h4>A NGINX Server with Lua support</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f69ee85bdc90e7a84fda8b32c52ea8c0/href">https://medium.com/media/f69ee85bdc90e7a84fda8b32c52ea8c0/href</a></iframe><p>To get started we pick <a href="https://hub.docker.com/r/openresty/openresty/">OpenResty’s Docker image</a>. This allows us to have lua-nginx-module support. First, we create a Makefile that allows one to run a container with NGINX having the files from the current directory mounted as a volume inside it.</p><p>Having that, you can run the container with make run. You can then update nginx.conf and issue make reload to reload the configuration.</p><p>Now, in the nginx.conf file we set three locations:</p><ul><li>/bearer-to-basic: replaces bearer authorization by basic authorization and then forwards the request to /auth-dump .</li><li>/basic-to-bearer: replaces ‘basic’ by ‘bearer’ authorization and forwards the request to /auth-dump .</li><li>/auth-dump: just responds with a 200 OK having the headers in the body.</li></ul><p>For each of these locations we attach a piece of Lua code for a given phase. These NGINX phases can be thought as steps in a pipeline that a request goes through.</p><p>Here we’re attaching to two of them: ‘rewrite’ and ‘content’. The first is used for rewriting variables and configurations of a request. The second, the content.</p><p>You can see more at <a href="http://www.nginxguts.com/2011/01/phases/">http://www.nginxguts.com/2011/01/phases/</a> and <a href="https://openresty.org/download/agentzh-nginx-tutorials-en.html">https://openresty.org/download/agentzh-nginx-tutorials-en.html</a>).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2b097b8d8c21116e94eb911129a43b6/href">https://medium.com/media/f2b097b8d8c21116e94eb911129a43b6/href</a></iframe><p>Now, having that setup, time to write the Lua scripts. Let’s start with the first, ‘auth-dump’. It doesn’t do much: once a request comes, it prints its headers to the response stream. Having this location as the proxy_pass of other directives allows us to very easily see the results of what we want — modify some headers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62d590ec086861370b5821406e4b6363/href">https://medium.com/media/62d590ec086861370b5821406e4b6363/href</a></iframe><p>Now, to the real thing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/acb778b5bc99950a1bcfee2efd077db7/href">https://medium.com/media/acb778b5bc99950a1bcfee2efd077db7/href</a></iframe><p>We start by setting some variables that are local to the module.</p><p>After that, require utils, a file under /etc/nginx that contains some basic utilities like isEmpty (see the file contents in the GitHub repository).</p><p>Then, we export a function from the module (yeah, just like with Javascript, you can expose objects/functions/variables from modules).</p><p>In the end, set the header and we’re done :)</p><p>—</p><p><em>If you have any questions/comments, leave them bellow or just reach me at </em><a href="https://twitter.com/beld_pro"><em>twitter.com/beld_pro</em></a><em> ✌️ 🐦</em></p><p><em>The code can be found at </em><a href="https://github.com/beldpro-ci/sample-basic-to-bearer-nginx"><em>https://github.com/beldpro-ci/sample-basic-to-bearer-nginx</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c665d5522f1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick Tip: Creating a PostgreSQL Container with default User and Password]]></title>
            <link>https://medium.com/@beld_pro/quick-tip-creating-a-postgresql-container-with-default-user-and-password-8bb2adb82342?source=rss-d33bc357db------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bb2adb82342</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[beld ]]></dc:creator>
            <pubDate>Sun, 30 Apr 2017 16:21:01 GMT</pubDate>
            <atom:updated>2017-04-30T16:21:01.344Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4io_io2GZmW2yObc0Y_YMg.jpeg" /></figure><p>Hey, just in case you want to set up a PostgreSQL database with a default user and password using Docker, here’s a very simple way that you can do.</p><h4>1. Extend the Postgres image to contain an initialization script that will create the user.</h4><p>From the documentation at <a href="https://hub.docker.com/_/postgres/">https://hub.docker.com/_/postgres/</a>, we can see that it supports adding a set of custom *init* scripts that allow us to initialize databases/users during the bootstrap time. All you’ve gotta do is add your script there and it’ll be ran.</p><p>So, that’s what I’ve done: created a `01-filladb.sh` file under `init` and then added that to the right path (`/docker-entrypoint-initdb.d`):</p><pre>.<br>├── Dockerfile<br>└── init<br> └── 01-filladb.sh</pre><pre>cat ./Dockerfile</pre><pre>FROM postgres:alpine<br>ADD ./init /docker-entrypoint-initdb.d/</pre><h4>2. Add the database initialization to the script</h4><p>Here is where your initialization code comes: you create the user, create a database and then grant privileges to the first.</p><p>As I want to make this extensible (so that I can reuse the image later with other users/databases), everything is parametrized using environment variables:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15b7f7e063dc732862de3df6096d47de/href">https://medium.com/media/15b7f7e063dc732862de3df6096d47de/href</a></iframe><h4>3. Build and Run</h4><p>You can either build a usual image (`docker build -t &lt;name&gt; .` — like, `docker build myuser/mytestdb .`) or add a build directive to a `docker-compose.yml` that automatically builds and uses the image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f4fc793fe0ec4ac769a35a7a7e3b62a/href">https://medium.com/media/1f4fc793fe0ec4ac769a35a7a7e3b62a/href</a></iframe><p>Now, just use docker-compose up to run it. You should see something like this in the end:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8e35d81b835cdd9296cf43df384d410/href">https://medium.com/media/a8e35d81b835cdd9296cf43df384d410/href</a></iframe><p>Now, just use `docker-compose up` to run it. You should see something like this in the end:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bf7a472b2a76e841f42a0ee4b6e2f1f/href">https://medium.com/media/7bf7a472b2a76e841f42a0ee4b6e2f1f/href</a></iframe><p>That’s it! If you have any questions you can reach me at <a href="http://twitter.com/beld_pro">@beld_pro</a> on Twitter at any time 🙌 If you need to upload a file right from your terminal, make sure you also give a try to <a href="https://filla.be/">https://filla.be</a> 👌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bb2adb82342" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing multiple processes in Docker containers]]></title>
            <link>https://medium.com/@beld_pro/managing-multiple-processes-in-docker-containers-455480f959cc?source=rss-d33bc357db------2</link>
            <guid isPermaLink="false">https://medium.com/p/455480f959cc</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[sysadmin]]></category>
            <category><![CDATA[process]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[systems-thinking]]></category>
            <dc:creator><![CDATA[beld ]]></dc:creator>
            <pubDate>Thu, 23 Mar 2017 03:59:43 GMT</pubDate>
            <atom:updated>2017-05-09T03:07:19.980Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3qwrhLxmOLa6Yo_Ijr5PFg.jpeg" /></figure><p>Even though the common practice states that one must create containers that have a single process running, it&#39;s common so see people facing the need for a multi-process approach.</p><p>A pretty good solution that i&#39;ve found is S6 (<a href="https://skarnet.org/software/s6/">https://skarnet.org/software/s6/</a>)<em> &quot;a collection of utilities revolving around process supervision and management, logging, and system initialization&quot;</em> (from the description) — after reading a blog post from Tutum (<a href="https://blog.tutum.co/2014/12/02/docker-and-s6-my-new-favorite-process-supervisor/">https://blog.tutum.co/2014/12/02/docker-and-s6-my-new-favorite-process-supervisor/</a>).</p><p>My context was simple; needed to run several processes and ensure that:</p><ul><li>if process A fails, process A must be restarted</li><li>processes A, B and C are supposed to not be ran as daemons and might occasionally fork (creating subprocesses)</li><li>doesn&#39;t require many configuration files</li><li>SIGTERM should be properly handled</li></ul><p>A sample demonstrating the end result can be found here: <a href="https://github.com/beldpro-ci/s6-entrypoint">https://github.com/beldpro-ci/s6-entrypoint</a>.</p><p>Going straight to the demonstration, the directory structure:</p><pre>.<br> ├── Dockerfile<br> ├── Makefile<br> ├── README.md<br> └── etc         // added to `/etc` of image<br> ├── bin<br> │ └── my-binary // main executable<br> └── s6<br> ├── lala<br> │ ├── finish    // lala “on-fail” script<br> │ └── run       // lala service start-up script<br> └── lulu<br>   ├── finish    // lulu “on-fail” script<br>   └── run       // lulu start-up script</pre><p>As S6 has the capabilities of a proper *init*, the Dockerfile is pretty simple: just fetches S6 and then sets the entrypoint:</p><pre>FROM alpine</pre><pre>RUN apk add — update s6 bash</pre><pre>ADD ./etc /etc</pre><pre>ENTRYPOINT [ “/bin/s6-svscan”, “/etc/s6” ]`</pre><p><em>/etc/s6</em> indicates a<em> scan directory</em>: a directory with a list of <em>service directories</em> — where scripts related to a given service reside. For instance, say that *lala* is a service (like nginx) that has a start script and that we also have *lulu*, another service, like rsyslog, which also has a start script. We&#39;d create a directory (in this case i created /etc/s6 — could have any name!) and then, for each service, add a directory (with the name of the service). Each service directory then receives a *run* script (name used by s6 to locate a start script).</p><p>And that&#39;s it! That&#39;s the enough to have your processes being supervised and its zombies taken care of. In the end, it looks like this:</p><pre><strong>s6-docker-demo git:(master) ✗ </strong>make</pre><pre>docker run s6test</pre><pre>Spawning lala</pre><pre>Spawning lulu</pre><p>The two processes are spawn concurrently, with a little trick of having *s6-supervise* processes taking care of our services:</p><pre><strong>~ </strong>docker top f5993ea33b59</pre><pre>PID USER TIME COMMAND</pre><pre>3136 root 0:00 /bin/s6-svscan /etc/s6</pre><pre>3156 root 0:00 s6-supervise lala</pre><pre>3157 root 0:00 s6-supervise lulu</pre><pre>3158 root 0:00 {my-binary} /bin/sh /etc/bin/my-binary</pre><pre>3160 root 0:00 {my-binary} /bin/sh /etc/bin/my-binary</pre><pre>3217 root 0:00 sleep 1</pre><pre>3218 root 0:00 sleep 1</pre><p>In the repository (<a href="https://github.com/beldpro-ci/s6-entrypoint">https://github.com/beldpro-ci/s6-entrypoint</a>) you can find more information as each little detail got documented over there.</p><p>What about you? How have you been doing multi-processes containers with Docker (if so)? Let me know if you&#39;ve got a good solution!</p><p><em>Hey, also, please let me know if i stated something incorrectly. I&#39;ll appreciate a lot! Thanks!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=455480f959cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>