<?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 Dave Elliott on Medium]]></title>
        <description><![CDATA[Stories by Dave Elliott on Medium]]></description>
        <link>https://medium.com/@david.w.elliott?source=rss-be819d7febf2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*d_-naP3uJF-7ZvEdnDKZyg.png</url>
            <title>Stories by Dave Elliott on Medium</title>
            <link>https://medium.com/@david.w.elliott?source=rss-be819d7febf2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 14:11:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@david.w.elliott/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[Local Docker Tips & Tricks]]></title>
            <link>https://medium.com/@david.w.elliott/local-docker-tips-tricks-82cad5224428?source=rss-be819d7febf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/82cad5224428</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Dave Elliott]]></dc:creator>
            <pubDate>Mon, 27 Apr 2020 02:55:39 GMT</pubDate>
            <atom:updated>2020-04-27T02:55:39.839Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MFF30ZROUuu2Jb4D" /><figcaption>Photo by <a href="https://unsplash.com/@guibolduc?utm_source=medium&amp;utm_medium=referral">Guillaume Bolduc</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In a previous article, I wrote about how we can look to inject quality early into the container lifecycle. In that article, I focused on linting Dockerfiles. I planned to expand further on how we can leverage available open-source tools to improve the security of containers. However, with the whole COVID-19 situation and trying to juggle work and family, the idea of sitting down and writing a decent length article has been a bit of a mental barrier. I decided rather than do nothing ( a strategy that I find rarely pays off) I’d throw down a few quick tips and tricks that make working with Docker on your local machine a little easier and then finish with a more concise and brief write up on how you can improve your workflow by a quick painless integration to Clair, an image vulnerability scanner. Hopefully, the result is images and containers that you can have a reasonable level of confidence in from both a quality and security perspective.</p><h3>Aliases and Laziness (a.k.a efficiency)</h3><p>First use aliases and shell functions to make your life easier. I have a few helpful aliases and functions defined in my bash_profile that making working with local Dockerfiles and containers easier and quicker:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ccPkD8HZs1v5ssKaPHMRCA.png" /></figure><p>These allow me to quickly lint Dockerfiles I’m working with, scan images using Clair and jump into containers I’m building in order to troubleshoot or inspect them.</p><p>Looking at each in more detail …..</p><h4>Hadolint</h4><p>I like to keep my code tidy and consistent and this also applies to my Dockerfiles, so I always lint them. I’m not always working with an IDE that has inbuilt linting so I have an alias that allows me to quickly lint any Dockerfiles I come across.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZwavWEORmdk6bRz7c1ZFew.png" /></figure><p>The alias simply runs hadolint in a container on your local machine and sends the Dockerfile to its stdin. At the end of the run the --rm option cleans up and removes the container after its finished.</p><p>You could get more advanced and expand the alias to pass hadolint a configuration file if you want to ignore specific rules but generally, I just apply them all.</p><p>Personally, I still prefer to use the docker builder pattern and add linting as the first stage of any Dockerfiles I create but this alias comes in very handy when working with Dockerfiles where that pattern hasn’t been applied.</p><h4>Troubleshooting and Inspecting</h4><p>I often find that there is a need to exec into a running container and have a nose around. Either to troubleshoot a container that isn’t behaving as expected or to have a look around a container that I haven’t built myself.</p><p>Generally, I’m dropping into an interactive Bourne or Bash shell but nothing is stopping you setting up for whatever your containers support .. ash, zsh, csh .. whatever. Just be aware not all containers you come across will have the specific shell you are wanting … some don’t even have any shell (built FROM scratch). The below shows a successful attempt at dropping into an interactive shell session on an openjdk container and an unsuccessful attempt on the hello-world container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FwQrvpVBCB4qeU7gxZzDsQ.png" /></figure><p>Once I exit the container the --rm option takes care of cleaning everything up.</p><h3>Reasonable Security via Clair</h3><p>You should be looking to run image and container scanning as part of your workflows, most likely this happens automagically for you at work via your organisation’s CI/CD workflows but it’s still something that you can look to incorporate into your personal projects or even just look to “shift left”. It’s never a bad thing to get quicker feedback by ad-hoc scanning whilst you are still developing your image.</p><p>To give me what I consider to be a “reasonable” level of comfort that what I’m producing is secure, I run a static analysis for vulnerabilities using Quay Enterprise’s open-source Clair (<a href="https://github.com/quay/clair">https://github.com/quay/clair</a>). This will scan my images and analyse them against a known list of common vulnerabilities and exposures (<a href="https://cve.mitre.org/">CVEs</a>). There are a bunch of ways to configure and setup Clair but it relies on two main components:</p><ul><li>A postgres database holding the CVE data</li><li>A Clair Server</li></ul><p>Images are passed to the server for scanning via its REST API or by using a pre-built client (the easier option).</p><p>One option is to build, configure and deploy the Clair server and DB on your local network and just run the client locally, but as this article is about local tips &amp; tricks I want to be able to run everything local to my laptop so I can scan images anytime and anywhere.</p><p>This is where <a href="https://github.com/arminc">Armin</a> has come to the rescue and done a great job for the community by providing a solution that allows standalone local scanning (<a href="https://github.com/arminc/clair-local-scan">https://github.com/arminc/clair-local-scan</a>). I use this solution and the Quay.io container scanner to run local containers that give me a fully populated CVE database, a Clair server, and a client. Now … remember I said “reasonable” security …. I’m pulling a pre-populated CVE database. I’ve no guarantee that its up-to-date or accurate. I’ve got no guarantee that any of the images aren’t poisoned. I’m completely trusting that all three components are legit …. On the plus side, they are open-source — the community has access to the code, so in theory any malicious additions should be caught. I consider it trusted enough to use for early testing to highlight any possible issues and for use in personal projects. I wouldn’t rely solely on it as a trusted solution in a corporate environment.</p><p>To scan a container we need to run the postgres CVE database and the Clair server as local containers and then use the containerised client to scan our image. All containers use the docker linking system so they can talk to one another.</p><p>Within my bash profile I define a function to handle the running of the postgres db and the Clair server and then define aliases for running a scan as well as cleaning up after I’m finished</p><p>We pull the latest DB and run the Clair server using the following function</p><pre>function clair() {<br> docker run -p 5432:5432 -d --name clair-db arminc/clair-db:latest<br>        sleep 5<br>        docker run --rm -p 6060:6060 --link clair-db:postgres -d --name clair arminc/clair-local-scan:latest<br>}</pre><p>This is simply invoked with the command</p><pre>$ clair</pre><p>For convenience, I then use the scan client in the clair-container-scan container to scan the debian:buster-slim image … a favourite base of many pythonista.</p><pre>$ clair_scan debian:buster-slim</pre><p>Under the hood, this alias executes the following docker run command.</p><pre>docker run --rm -i -t --link clair:clair -v /var/run/docker.sock:/var/run/docker.sock quay.io/usr42/clair-container-scan</pre><p><strong>Notes</strong>: Firstly, if you’re not comfortable with giving the clair-container-scan access to your host docker socket then another option is to install Armin’s clair-scanner client locally and use that to run the scan instead (<a href="https://github.com/arminc/clair-scanner">https://github.com/arminc/clair-scanner</a>), or if you want complete control over what is happening on the client side use the REST API. I don’t recommend blindly pulling untrusted containers and running them. Always best to first inspect it, validate what it’s doing and then run your local validated version. Secondly, the shell function could also be replaced with docker compose to setup and run the server and db. It’s a more elegant solution, I just don’t use compose that much as most of my containers end up in a k8s cluster so it was quicker for me to update my bash_profile.</p><p>When using the clair-container-scan the output of the scan is returned as a json formatted report on stdout, a snippet of which is shown below:</p><pre>[<br>  {<br>    &quot;image&quot;: &quot;debian:buster-slim&quot;,<br>    &quot;vulnerabilities&quot;: [<br>      {<br>        &quot;featurename&quot;: &quot;glibc&quot;,<br>        &quot;featureversion&quot;: &quot;2.28-10&quot;,<br>        &quot;vulnerability&quot;: &quot;CVE-2016-10228&quot;,<br>        &quot;namespace&quot;: &quot;debian:10&quot;,<br>        &quot;description&quot;: &quot;The iconv program in the GNU C Library (aka glibc or libc6) 2.25 and earlier, when invoked with the -c option, enters an infinite loop when processing invalid multi-byte input sequences, leading to a denial of service.&quot;,<br>        &quot;link&quot;: &quot;<a href="https://security-tracker.debian.org/tracker/CVE-2016-10228">https://security-tracker.debian.org/tracker/CVE-2016-10228</a>&quot;,<br>        &quot;severity&quot;: &quot;Low&quot;,<br>        &quot;fixedby&quot;: &quot;&quot;<br>      },<br>      {<br>        &quot;featurename&quot;: &quot;shadow&quot;,<br>        &quot;featureversion&quot;: &quot;1:4.5-1.1&quot;,<br>        &quot;vulnerability&quot;: &quot;CVE-2018-7169&quot;,<br>        &quot;namespace&quot;: &quot;debian:10&quot;,<br>        &quot;description&quot;: &quot;An issue was discovered in shadow 4.5. newgidmap (in shadow-utils) is setuid and allows an unprivileged user to be placed in a user namespace where setgroups(2) is permitted. This allows an attacker to remove themselves from a supplementary group, which may allow access to certain filesystem paths if the administrator has used \&quot;group blacklisting\&quot; (e.g., chmod g-rwx) to restrict access to paths. This flaw effectively reverts a security feature in the kernel (in particular, the /proc/self/setgroups knob) to prevent this sort of privilege escalation.&quot;,<br>        &quot;link&quot;: &quot;<a href="https://security-tracker.debian.org/tracker/CVE-2018-7169">https://security-tracker.debian.org/tracker/CVE-2018-7169</a>&quot;,<br>        &quot;severity&quot;: &quot;Low&quot;,<br>        &quot;fixedby&quot;: &quot;&quot;<br>      }<br>    ]<br>  }<br>]</pre><p>By default all vulnerabilities are output in the report. Once you’re done scanning remember to clean up and remove the db and Clair server containers using the clair_clean alias.</p><p>The clair-scanner can be tuned to whitelist CVE, or filter by severity threshold ….. but I’ll not cover that in this article. In fact it’s a good opportunity to use one of our aliases and have a snoop around within the clair-container-scan container to understand what it is doing. Docker inspect tells us where our entrypoint is and then it is a case of following the breadcrumbs …..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b8eMCHt5tMDeJ7QcPMUHww.png" /></figure><h4>Finally</h4><p>I hope this short article is enough to give you some ideas on how you can accelerate your docker development and shown how you can incorporate Clair to understand how vulnerable, or otherwise, your images are.</p><p>Have fun poking around with docker, stay home and take care of yourselves … and as always, if you see any mistakes, omissions or ways to improve I’d love to get your feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82cad5224428" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerfile Linting: Every time, Everywhere]]></title>
            <link>https://medium.com/@david.w.elliott/dockerfile-linting-every-time-everywhere-d8d271a1e650?source=rss-be819d7febf2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8d271a1e650</guid>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Dave Elliott]]></dc:creator>
            <pubDate>Tue, 03 Mar 2020 01:47:48 GMT</pubDate>
            <atom:updated>2020-03-03T01:47:48.012Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYI8th29YwKxFSFIw2oJYg.png" /></figure><p>Recently I’ve been looking at strategies on how to ratchet up quality in docker workflows. I’m a strong believer in building quality in as early as possible and the earliest point in the docker container lifecycle is the Dockerfile.</p><p>Docker Inc. provides a documented set of <a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/">best practices for writing Dockerfiles</a>. These are a great foundation for building efficient images but rely on the engineer knowing those practices and having the discipline to implement them. Humans are fallible and that’s where a linter comes in handy. A Dockerfile linter is a tool that analyses and parses the Dockerfile and warns when it doesn’t match best practices or guidelines. This gives us an automated way of helping engineers to write Dockerfiles which always meet a reasonable standard. Incorporating a linter into the workflow ensures our Dockerfiles are always readable, understandable and maintainable.</p><p>There are several Dockerfile linters out there but one of the better ones is <a href="https://github.com/hadolint/hadolint">Hadolint</a>. Hadolint not only lints the docker instructions, but it also incorporates <a href="https://github.com/koalaman/shellcheck">ShellCheck</a> which lints any bash or sh code used in the docker RUN instructions. This addition alone makes it a worthy choice, most engineers know how ugly and inscrutable shell commands can become if thrown haphazardly together with a few pipes, an awk, a grep and a bunch of cats.</p><p>Hadolint can be integrated into the docker workflow in a number of places: it is supported by a number of Editors and IDE, it can integrate with numerous modern CI tools and can also be integrated into code review platforms. This gives us plenty of options to play with when considering how to inject linting into the workflow. Whenever I look at implementing workflow improvements I try to focus on simplicity, portability, and repeatability. Ideally, I want any quality checks to be:</p><ul><li>low-friction (ideally transparent to the engineer or developer)</li><li>automatic</li><li>portable</li></ul><p>Any such validation checks should work in the same way whether I’m running them locally on my laptop, remotely on a cloud-hosted virtual machine, or if I’m triggering them within CI pipelines. They also should not rely on a human to trigger them. This is mainly for two reasons: one, I want engineers and developers to be focused on writing awesome code, designing solutions or solving problems … not wasting precious brainpower on making sure Dockerfiles are written to best practices and two, not all engineers run IDEs or remember to lint Dockerfiles before check-in.</p><p>My initial integration focused on integrating hadolint into the Jenkins CI pipelines. This seemed a logical place as it meant that it didn’t rely on a particular IDE or editor being used and it could be automated to run on every feature branch commit.</p><p>There are a couple of options for CI integration. One is to install hadolint onto the Jenkins slave, or in my case, bake it into the slave docker image. Once done, linting a Dockerfile is as simple as running the command:</p><pre>hadolint Dockerfile</pre><p>Another option, if the slave has access to a docker engine is to run hadolint within a container itself and redirect the Dockerfile to it:</p><pre>docker run --rm -i hadolint/hadolint &lt; Dockerfile</pre><p>Both options work fine and allow Dockerfiles to be automatically linted once committed to a source code manager and picked up by the CI server.</p><p>The linter can also be configured via commandline options or a yaml configuration file to ignore certain rules, as well as warning when images are being pulled from untrusted registries. The latter option is a fuss-free way of ensuring that engineers aren’t pulling untrusted containers from public registries and ensuring that they pull containers only via the company’s repository manager.</p><pre>ignored:<br>  - DL3000<br>  - DL3007</pre><pre>trustedRegistries:<br>  - company.com:8080</pre><p>If running locally, the configuration file can be passed directly via the ‘’-- config” option. When using docker run to execute the hadolint container it can be passed in by bind mounting a local volume. In the example below we bind mount the current working directory to /context in the container:</p><pre>$ find .<br>.<br>./linter<br>./linter/hadolint.yaml<br>./Dockerfile</pre><pre>$ docker run --rm -i -v ${PWD}:/context hadolint/hadolint \<br>&quot;/bin/hadolint&quot; &quot;--config&quot; &quot;/context/linter/hadolint.yaml&quot; &quot;/context/Dockerfile&quot;</pre><p>As a concept this is OK but it’s not great that this all happens post-commit and relies on the CI tooling to implement. It just isn’t portable. I wanted a solution that would run on my laptop, or any other engineers laptop for that matter, just as well as it would in the CI pipeline. It also needed to “just work” … anytime anyone built a docker image, anywhere, on any host I wanted it to be linted. That’s a lot of “anys”. Given engineers generally use a wide variety of local development environments in terms of IDE, Editors, even Operating Systems it seemed an insurmountable challenge at first. But then Docker itself came to the rescue!</p><p>By leveraging Multi-Stage builds which came in with Docker 17.05 and higher, it is possible to make linting a part of every docker build process. Multi-stage builds allow you to use multiple FROM statements in the Dockerfile. Each FROM statement can use a different base image and starts a new stage of the build, discarding the previous stage’s layers.</p><p>When running docker build it uses a Dockerfile and a context, the context simply being a specified URL or PATH to a set of files that can be accessed during the build process. By running linting as the first stage of a multi-stage build and passing the Dockerfile and the hadolint config yaml in as part of the context, we can effectively get the build process to lint its own Dockerfile.</p><p>The below Dockerfile shows this in practice. The first stage of the build uses a hadolint base image and the RUN command to execute the linting, followed by a second stage which builds the image we actually want — in this case a centos container which simply does an echo “Hello World!” when run.</p><pre># First Stage - Linting<br>FROM hadolint/hadolint:v1.17.5-6-gbc8bab9-alpine as config</pre><pre># Copy the dockerfile and linter config from the context<br>COPY config/hadolint.yaml /config/<br>COPY Dockerfile .</pre><pre># Execute the linting process<br>RUN echo &quot;### Linting Dockerfile ###&quot; &amp;&amp; /bin/hadolint --config /config/hadolint.yaml Dockerfile</pre><pre># Second Stage - Our final image<br>FROM centos:centos7</pre><pre>ENTRYPOINT [&quot;echo&quot;, &quot;Hello World!&quot;]</pre><p>Given the following dir structure:</p><pre>Dockerfile<br>/config/hadolint.yaml</pre><p>We run docker build from the top-level directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8QAeXZOtJPyhWMom_2eE6Q.png" /></figure><p>And confirming that our resultant container is what we expect</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*25YUrC-dMFi9vHBbKs5K7w.png" /></figure><p>If the linter generates warnings then the build process halts. In the case below the config is set so that engineers can only pull images from the company private registry.</p><pre>ignored:<br>  - DL3000</pre><pre>trustedRegistries:<br>  - my-company.com:5000</pre><p>This results in warnings being generated for lines 2 and 10 of the Dockerfile respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8d_gl_hbZFEc5OrqSSBtOA.png" /></figure><p>Similarly, it will stop the build if we use an ADD statement rather than COPY to add files or folders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Onm0bXTlWt6EClpcJvoL3g.png" /></figure><p>Adding some dubious shell commands to the Dockerfile demonstrates the linter running ShellCheck against the RUN instructions and catching the “Useless Use of Cat”.</p><pre>RUN echo &quot;Hello&quot; &gt; /tmp/hello.txt<br>RUN cat /tmp/hello.txt | wc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*plvrrHtxcunLnPAvUrXWfQ.png" /></figure><p>The full list of rules, error codes and rationale is available on the hadolint github pages.</p><p>So there we have it. An easy way to ensure that no matter where engineers are building images they are always performing and passing linting. The true beauty of this method is that is contained within the Docker build process itself. Wherever the Dockerfile is built, is where it is linted. On my laptop, in the cloud, in CI pipelines, on other engineer’s laptops…..</p><p>Linting: Every time, Everywhere.</p><p>As always, appreciate any feedback or comments, especially if its to point out further improvements !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8d271a1e650" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>