<?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[Travis on Docker - Medium]]></title>
        <description><![CDATA[My posts about Docker. - Medium]]></description>
        <link>https://medium.com/travis-on-docker?source=rss----74c8ebbb9390---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Travis on Docker - Medium</title>
            <link>https://medium.com/travis-on-docker?source=rss----74c8ebbb9390---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 03:53:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/travis-on-docker" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Microcontainers — Tiny, Portable Docker Containers]]></title>
            <link>https://medium.com/travis-on-docker/microcontainers-tiny-portable-docker-containers-1507e3bf8688?source=rss----74c8ebbb9390---4</link>
            <guid isPermaLink="false">https://medium.com/p/1507e3bf8688</guid>
            <category><![CDATA[microcontainers]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Travis Reeder]]></dc:creator>
            <pubDate>Tue, 12 Sep 2017 22:13:41 GMT</pubDate>
            <atom:updated>2020-11-13T11:26:18.598Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*Y75S4raPSor6QCl1VXhdpQ.png" /></figure><p><a href="http://docker.com/">Docker</a> enables you to package up your application along with all of the application’s dependencies into a nice self-contained image. You can then use use that image to run your application in containers. The problem is you usually package up a lot more than what you need so you end up with a huge image and therefore huge containers. Most people who start using Docker will use Docker’s <a href="https://hub.docker.com/explore/">official repositories</a> for their language of choice, but unfortunately if you use them, you’ll end up with images the size of the empire state building when you could be building images the size of a bird house. You simply don’t need all of the cruft that comes along with those images. If you build a Node image for your application using the <a href="https://hub.docker.com/r/library/node/">official Node image</a>, it will be a <strong>minimum of 643 MB </strong>because that’s the <a href="https://imagelayers.iron.io/?images=node:5.4.1">size of the official Node image</a>.</p><p>I created a simple <a href="https://github.com/treeder/tiny-node-docker">Hello World Node app</a> and built it on top of the official Node image and it weighs in at 644MB.</p><p>That’s huge! My app is less than 1 MB with dependencies and the Node.js runtime is ~20MB, what’s taking up the other ~620 MB?? We must be able to do better.</p><h3>What is a Microcontainer?</h3><p>A Microcontainer contains only the OS libraries and language dependencies required to run an application and the application itself. Nothing more.</p><p>Rather than starting with everything but the kitchen sink, start with the<strong> bare minimum and add dependencies</strong> on an as needed basis.</p><p>Taking the exact same Node app above, using a really small base image and installing just the essentials, namely Node.js and its dependencies, it comes out to 29MB. A full <strong>22 times smaller</strong>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*2ajjRF_OZ4e_v_v08fxKNA.png" /><figcaption>Regular Image vs MicroImage</figcaption></figure><p>Try running both of those yourself right now if you’d like, docker run –rm -p 8080:8080 treeder/tiny-node:fat, then docker run –rm -p 8080:8080 treeder/tiny-node:latest. Exact same app, vastly different sizes.</p><h3>Why Are Microcontainers Great?</h3><p>There are many benefits to using MicroContainers:</p><ul><li><strong>Size</strong> — MicroContainers are small. As shown above, without changing any code the image is 22 times smaller than a typical image.</li><li><strong>Fast/Easy Distribution</strong> — Because the size is so much smaller, it’s much quicker to download the image from a Docker registry (eg: <a href="https://hub.docker.com/">Docker Hub</a>) and therefore it can be distributed to different machines much quicker.</li><li><strong>Improved Security</strong> — Less code/less programs in the container means less attack surface. And, the base OS can be more secure (more below).</li></ul><p>These benefits are similar to the benefits of <a href="https://en.wikipedia.org/wiki/Unikernel#Benefits_and_drawbacks">Unikernels</a>, with none of the drawbacks.</p><h3>How to Build Microcontainers</h3><p>The base image for all Docker images is the `<a href="https://hub.docker.com/_/scratch/">scratch</a>` image. It has essentially nothing in it. This may sound useless, but you can actually use it to <a href="http://iron.io//blog/2015/07/an-easier-way-to-create-tiny-golang-docker-images.html">create the smallest possible image</a> for your application, if you can compile your application to a static binary with zero dependencies like you can with Go or C. For instance, my <a href="https://hub.docker.com/r/treeder/static-go/">treeder/static-go image</a> contains a Go web app and the entire image including my app is 5MB.</p><p>That’s about as small as you can get. The scratch image + your application binary.</p><p>Not everyone is using Go (unfortunately) so you’ll probably have more dependencies and you’ll want something with a bit more than the scratch image. Enter <a href="http://www.alpinelinux.org/">Alpine Linux</a>. I won’t bore you with the details, but their tagline says it all: “Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.” You can read more about what each of those things mean <a href="http://www.alpinelinux.org/about/">here</a>, but what we care the most about for this article is the “lightweight” part. The base Alpine image is only 5MB:</p><p>So now we have a very nice OS as a base with a <a href="https://pkgs.alpinelinux.org/packages">nice package system</a> to add our dependencies. For our simple Node app, we only need Node itself so we can just add the Node package and nothing else. Our Dockerfile looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3999d023cefed89e482dc220802129a/href">https://medium.com/media/e3999d023cefed89e482dc220802129a/href</a></iframe><p>Simple and clean. We only have Node and what Node needs in the image now.</p><p>Now to add our code to the image, it’s just a few more lines in our Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b380e15470eb7ff09a65c2286c34212/href">https://medium.com/media/4b380e15470eb7ff09a65c2286c34212/href</a></iframe><p>You can grab sample code and see the <a href="https://github.com/treeder/tiny-node-docker">full build instructions here</a>, but you get the idea. We now have a very small OS + <em>only</em> the dependencies we need + our application code. Nothing more.</p><p>The same rules apply to all languages.</p><h3>Base Images for all Languages</h3><p>As luck would have it, we’ve already built base images for all major languages and you can find them here:</p><p><a href="https://github.com/fnproject/dockers">https://github.com/fnproject/dockers</a></p><p>These have some optimizations in them to make them as small as possible and we update them regularly, which makes them a slightly better choice than doing it yourself. Using the Iron.io base images, the Dockerfile above for the Node app changes to this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38e04f70bd4e14bc05bd0063544c87fa/href">https://medium.com/media/38e04f70bd4e14bc05bd0063544c87fa/href</a></iframe><p>Also, for every language, we built two versions of the image. one for building and one for running. The images for building have all the build tools in them so are generally much bigger than the ones for running.</p><p>For instance, to build your Node dependencies, you’d use iron/node:dev like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bdaaf9d7a87ff2179498e291560a9c1/href">https://medium.com/media/7bdaaf9d7a87ff2179498e291560a9c1/href</a></iframe><p>Then use iron/node in your Dockerfile or to run it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0e677e2f6f04215e7c58992eec07ea8/href">https://medium.com/media/b0e677e2f6f04215e7c58992eec07ea8/href</a></iframe><p>Same goes for all the other languages, but you’d use their build/vendor/run commands.</p><p>If you’d like to use a different version of a language, you can change the tag. For instance, you could use iron/node:4.1 or iron/node:0.12. You can find all the version tags on Docker Hub for each language. The Node tags are here for instance: <a href="https://hub.docker.com/r/iron/node/tags/">https://hub.docker.com/r/fnproject/node/tags/</a>. You’ll find links to all the other Docker Hub tags from the <a href="https://github.com/fnproject/dockers">fnproject/dockers</a> repo.</p><h3>How to Build and Package for All Languages</h3><p>This probably isn’t luck anymore, but we also have examples of using the above base images for most major languages here:</p><p><a href="https://github.com/iron-io/dockerworker">https://github.com/iron-io/dockerworker</a></p><p>If you look at the README’s for each language in that repository, it will walk you through how to build your dependencies, test your code, build a small Docker image and test the image.</p><h3>No Going Back</h3><p>After reading this post, you should be able to create Docker images for your applications that contain nothing more than what is required to run your app. A container is essentially an instance of an image, so once you start firing up containers using your image, you’ve entered the world of Microcontainers. And there’s no going back.</p><blockquote><em>Just used your “tiny image” technique on one of my golang repos. Its awesome! thanks for the great post. shrunk it down to 5mb amazing. — Harlow Ward @ Clearbit</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1507e3bf8688" width="1" height="1" alt=""><hr><p><a href="https://medium.com/travis-on-docker/microcontainers-tiny-portable-docker-containers-1507e3bf8688">Microcontainers — Tiny, Portable Docker Containers</a> was originally published in <a href="https://medium.com/travis-on-docker">Travis on Docker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Triple-Stage Docker Builds with Go and Angular]]></title>
            <link>https://medium.com/travis-on-docker/triple-stage-docker-builds-with-go-and-angular-1b7d2006cb88?source=rss----74c8ebbb9390---4</link>
            <guid isPermaLink="false">https://medium.com/p/1b7d2006cb88</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Travis Reeder]]></dc:creator>
            <pubDate>Wed, 16 Aug 2017 05:20:07 GMT</pubDate>
            <atom:updated>2017-08-16T05:20:06.855Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QW6tkBQBH46i1I1e7FWYqg.jpeg" /></figure><p>In a previous post I talked about <a href="https://medium.com/travis-on-docker/multi-stage-docker-builds-for-creating-tiny-go-images-e0e1867efe5a">multi-stage builds for creating small images</a> from a single Dockerfile. In this post, we’ll take it a step further by doing 2 build steps, one for a Go backend API, another to compile an Angular application, plus a final step to extract the build artifacts and put them in a final, minimal image.</p><p>It also takes advantage of Docker caching so it will only rebuild layers when there are changes, for instance, it won’t re-fetch dependencies unless you change your dependencies and it won’t compile your code unless it’s been changed.</p><p>I won’t post all the code here, just the Dockerfile, but it should work with any project that has a Go API and an Angular frontend that talks to the API. Which is a great combo BTW!</p><p>Prerequisites:</p><ul><li>This uses the new Go <a href="https://github.com/golang/dep">dep tool</a> which shouldn’t be too hard to add to your project, just follow the <a href="https://github.com/golang/dep#setup">Setup instructions</a>.</li><li>Your API should serve static files from ../ui/dist , eg: http.ServeFile(w, r, “../ui/dist/index.html”)</li><li>You should be using <a href="https://cli.angular.io/">Angular CLI</a>.</li><li>And of course you must have <a href="http://docker.com/">Docker</a> installed.</li></ul><p>That’s about it.</p><h4>The Dockerfile</h4><p>Here’s the full Dockerfile, you can copy it into your Dockerfileand modify as you see fit:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fb51e2163fc747b3ea2c6db705a4cf2/href">https://medium.com/media/5fb51e2163fc747b3ea2c6db705a4cf2/href</a></iframe><p>1) The first stage builds the Go API. It first fetches the Go dependencies using the dep tool, then builds the final binary. The dependency part goes first so that it can use Docker’s cache to make subsequent builds run faster.</p><p>2) The next stage builds the Angular application in the same fashion: first get dependencies then build the final Javascript code to use in production.</p><p>3) The final stage takes the Go binary and the compiled Angular application and stuffs them into a small alpine image that doesn’t contain any of the Go tools nor the node, npm and angular tools required to build the Angular app.</p><h4>Usage</h4><p>The one thing you’ll have to change for sure is the following line:</p><pre>ENV D=/go/src/github.com/USERNAME/REPONAME</pre><p>Change it the correct path for your Go project.</p><p>And you’ll probably have to modify your Go code a bit to serve up files from the ../ui/dist/ directory or modify the Dockerfile a bit to match your code, but this should give you a good idea of how to make this work.</p><p>Then it’s just a simple:</p><pre>docker build -t USERNAME/REPONAME .</pre><p>Boom.</p><h4>Conclusion</h4><p>Multi-stage Docker builds have really made things a lot nicer. Previously if you wanted a small image, you used to have to write your own multi-stage scripts, mount drives, and copy output between steps from your local file system into a final image. Now it’s all wrapped up into a single Dockerfile with a single docker build command. Nice and clean.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b7d2006cb88" width="1" height="1" alt=""><hr><p><a href="https://medium.com/travis-on-docker/triple-stage-docker-builds-with-go-and-angular-1b7d2006cb88">Triple-Stage Docker Builds with Go and Angular</a> was originally published in <a href="https://medium.com/travis-on-docker">Travis on Docker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Run Dockerized Apps on Heroku… and it’s pretty sweet]]></title>
            <link>https://medium.com/travis-on-docker/how-to-run-dockerized-apps-on-heroku-and-its-pretty-great-76e07e610e22?source=rss----74c8ebbb9390---4</link>
            <guid isPermaLink="false">https://medium.com/p/76e07e610e22</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Travis Reeder]]></dc:creator>
            <pubDate>Fri, 30 Jun 2017 15:01:38 GMT</pubDate>
            <atom:updated>2017-06-30T18:41:48.594Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*LG6LBEkLkiKov13CsnaPaw.jpeg" /></figure><p>Every cloud provider is supporting <a href="http://docker.com/">Docker</a> now, but I have to say, <a href="http://heroku.com/">Heroku</a> nailed it. This seems to have run under the radar for the most part since I haven’t heard anyone talk about it. It reminds me of the good ol’ days when Heroku first started. Their entire pitch and tagline was git push heroku master, then magic happened. And now they’ve done the same with docker push. The only other service that is as simple is <a href="http://hyper.sh/">Hyper.sh</a>, but Heroku has a few advantages like a built in load balancer, the ability to scale and many years of working out the kinks.</p><h4>Dockerizing an App</h4><p>First, let’s start with a simple Hello World web app. This is in Go, but could be any language.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/495f3688dce84540514a2d94a2c08872/href">https://medium.com/media/495f3688dce84540514a2d94a2c08872/href</a></iframe><p>And we need a Dockerfile to build our Docker image (requires Docker 17.05+):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5abf8ad6ebcde046d77f37789f2510f/href">https://medium.com/media/a5abf8ad6ebcde046d77f37789f2510f/href</a></iframe><p>You can test this if you want with a simple:</p><pre>docker build -t treeder/myapp .<br>docker run --rm -it -p 8080:8080 treeder/myapp</pre><p>Then surf to <a href="http://localhost:8080/">http://localhost:8080</a> to see that it works.</p><p>Now I’ll show you two ways to deploy your app to Heroku.</p><h4>Push to Heroku with Heroku CLI</h4><p>This assumes you already have the Heroku CLI installed. Install the Heroku container registry plugin for the cli:</p><pre>heroku plugins:install heroku-container-registry</pre><p>Login to the registry:</p><pre>$ heroku container:login</pre><p>Now create a Heroku app:</p><pre>heroku create</pre><p>That command will return an app name, copy it to use it for the next command.</p><pre>heroku container:push web --app ${YOUR_APP_NAME}</pre><p>And boom, that’s it. It will build your image and push it to Heroku. Check out your live app with:</p><pre>heroku open --app ${YOUR_APP_NAME}</pre><h4>Push to Heroku with Docker only</h4><p>The following is good if you’re deploying to Heroku with your CI tool and/or don’t want to install the Heroku CLI.</p><p>You’ll need to get your Heroku token which you can get from the cli on any machine that’s logged into Heroku:</p><pre>heroku auth:token</pre><p>Grab the returned token and from this point on, you don’t need Heroku CLI anymore.</p><p>Use the token to login to the Heroku Registry:</p><pre>docker login --username=_ --password=${YOUR_TOKEN} registry.heroku.com</pre><p>Note: The email and username are actually the underscore, don’t change those.</p><p>And then just push your image:</p><pre>docker build -t registry.heroku.com/${YOUR_APP_NAME}/web .<br>docker push registry.heroku.com/${YOUR_APP_NAME}/web</pre><p>Now surf to your Heroku app again and you’ll see it live.</p><h4>Conclusion</h4><p>Pretty dang awesome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76e07e610e22" width="1" height="1" alt=""><hr><p><a href="https://medium.com/travis-on-docker/how-to-run-dockerized-apps-on-heroku-and-its-pretty-great-76e07e610e22">How to Run Dockerized Apps on Heroku… and it’s pretty sweet</a> was originally published in <a href="https://medium.com/travis-on-docker">Travis on Docker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Cross Compile Go Programs using Docker]]></title>
            <link>https://medium.com/travis-on-docker/how-to-cross-compile-go-programs-using-docker-beaa102a316d?source=rss----74c8ebbb9390---4</link>
            <guid isPermaLink="false">https://medium.com/p/beaa102a316d</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Travis Reeder]]></dc:creator>
            <pubDate>Mon, 08 May 2017 18:23:22 GMT</pubDate>
            <atom:updated>2015-07-09T23:31:42.318Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*p53NGW177IWhNpcQetyXsw.png" /></figure><p>There are <a href="https://github.com/davecheney/golang-crosscompile">several</a> <a href="https://github.com/laher/goxc">ways</a> to <a href="http://stackoverflow.com/questions/12168873/cross-compile-go-on-osx">cross compile</a> Go programs, but the way I’m about to show you is awesome because you don’t have to install any libs or anything. That said, you do need <a href="http://docker.com/">Docker</a> installed, but you already have that anyways, right?</p><p>We use this to create our <a href="http://iron.io/">Iron.io</a> <a href="https://github.com/iron-io/ironcli">command line tool</a> binaries. You can find our tool and build scripts here: <a href="https://github.com/iron-io/ironcli">https://github.com/iron-io/ironcli</a></p><p>First off, be sure you’ve vendored your dependencies. There are <a href="https://github.com/golang/go/wiki/PackageManagementTools">various ways to do this</a>, but if you’re using godep, use <em>godep save -r </em>to rewrite imports so it doesn’t need any special GOPATH changes. Like I suggest in my <a href="https://medium.com/iron-io-blog/why-and-how-to-use-docker-for-development-a156c1de3b24">Docker for Development post</a>, vendor everything! It’s the best way to roll.</p><p>Now just run the following magical command after modifying the path and binary name:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa2e08d57dc78dd8a6ca76b89fd45f5b/href">https://medium.com/media/fa2e08d57dc78dd8a6ca76b89fd45f5b/href</a></iframe><p>Boom! After this runs you’ll have 6 binaries, two for each architecture (32 bit and 64 bit) for each operating system (Linux, Mac and Windows). If yoou want it built for other OS’s and ARCH’s, you can find the <a href="https://golang.org/doc/install/source#environment">full list here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=beaa102a316d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/travis-on-docker/how-to-cross-compile-go-programs-using-docker-beaa102a316d">How to Cross Compile Go Programs using Docker</a> was originally published in <a href="https://medium.com/travis-on-docker">Travis on Docker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Easier Way to Create Tiny Golang Docker Images]]></title>
            <link>https://medium.com/travis-on-docker/an-easier-way-to-create-tiny-golang-docker-images-7ba2893b160?source=rss----74c8ebbb9390---4</link>
            <guid isPermaLink="false">https://medium.com/p/7ba2893b160</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Travis Reeder]]></dc:creator>
            <pubDate>Thu, 27 Apr 2017 20:23:53 GMT</pubDate>
            <atom:updated>2015-07-31T18:20:10.293Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AemYIFm92tl5RW9nBzNSAw.jpeg" /></figure><p>Atlassian just posted a blog post about creating <a href="https://developer.atlassian.com/blog/2015/07/osx-static-golang-binaries-with-docker/?utm_source=golangweekly&amp;utm_medium=email">Static Go binaries with Docker on OSX</a> which shows how to make a tiny little Docker image (~6MB total) with your Go program inside. When I read it, I thought “this is cool… but <em>way</em> too complicated”. I’ve been using Docker a <strong>lot </strong>lately and knew there had to be an easier way. Here is that way.</p><p>So we have our little Go program, this one being a simple web server using <a href="http://www.gorillatoolkit.org/pkg/mux">Gorilla mux</a> for routing:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b67344cb66b9778ed40b7a27e956a73/href">https://medium.com/media/8b67344cb66b9778ed40b7a27e956a73/href</a></iframe><p>Now let’s get down to business.</p><h3>1. Vendor Dependencies</h3><p>The first thing we want to do is vendor our dependencies. We’re going to use <a href="https://github.com/tools/godep">godep</a> here:</p><pre>go get github.com/gorilla/mux<br>godep save -r</pre><h3>2. Build Static Binary</h3><p>Now we build a static binary for our program. Yes, this looks scary, but just copy and paste it and you’re golden:</p><pre>docker run --rm -it -v &quot;$GOPATH&quot;:/gopath -v &quot;$(pwd)&quot;:/app -e &quot;GOPATH=/gopath&quot; -w /app golang:1.4.2 sh -c &#39;CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags=&quot;-s&quot; -o hello&#39;</pre><p>You’ll end up with a binary called `hello`.</p><h3>3. Build Tiny Docker Image</h3><p>Now we embed that `hello` binary in the smallest Docker image possible. The Dockerfile looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59fb10a58e4c6b93b7c07f9c9b706a68/href">https://medium.com/media/59fb10a58e4c6b93b7c07f9c9b706a68/href</a></iframe><p>Now that we have the Dockerfile, just run:</p><pre>docker build -t treeder/go-hello-http .</pre><blockquote>That will build an image named `treeder/go-hello-http` and it should only be about <strong>~4MB!!</strong></blockquote><h3>4. Run/Test It</h3><p>Now run it:</p><pre>docker run --rm -it -p 8080:8080 treeder/go-hello-http</pre><p>Surf to: <a href="http://localhost:8080/">http://localhost:8080/</a> . Boom.</p><p>That’s it. You now have a super simple, super tiny Docker image containing your Go program. If you want to share it with people, push it up to Docker hub and tell people to `docker run your/image`.</p><p>All the source code and everything can be found here: <a href="https://github.com/treeder/tiny-golang-docker">https://github.com/treeder/tiny-golang-docker</a></p><p>If you want to read more about developing your apps with Docker, check out my previous post:</p><p><a href="https://medium.com/p/a156c1de3b24">Why and How to Use Docker for Development</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ba2893b160" width="1" height="1" alt=""><hr><p><a href="https://medium.com/travis-on-docker/an-easier-way-to-create-tiny-golang-docker-images-7ba2893b160">An Easier Way to Create Tiny Golang Docker Images</a> was originally published in <a href="https://medium.com/travis-on-docker">Travis on Docker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Overhead of Docker Run]]></title>
            <link>https://medium.com/travis-on-docker/the-overhead-of-docker-run-f2f06d47c9f3?source=rss----74c8ebbb9390---4</link>
            <guid isPermaLink="false">https://medium.com/p/f2f06d47c9f3</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Travis Reeder]]></dc:creator>
            <pubDate>Tue, 11 Oct 2016 17:10:36 GMT</pubDate>
            <atom:updated>2016-10-11T21:49:59.842Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X33hD7KSK64pIrUNLgqC-A.jpeg" /></figure><p>We use <a href="http://docker.com/">Docker</a> a lot. Like a <a href="http://www.infoworld.com/article/3112875/application-development/lessons-from-launching-billions-of-docker-containers.html">lot</a>, <a href="https://www.iron.io/docker-in-production-what-weve-learned/">lot</a>. While we love it for a lot of things, it still has a lot of room for improvement. One of those areas that could use improvement is the startup/teardown time of running a container.</p><h3>The Test</h3><p>To test the overhead of running a Docker container, I made a script that compares execution times for various <em>docker run</em> options vs not using Docker at all. The script that I’m running is a simple hello world shell script that consists of the following:</p><pre>echo &quot;Hello World!&quot;</pre><p>The base Docker image is the <a href="https://hub.docker.com/_/alpine/">official Alpine linux image</a> plus the script above.</p><h3>4 Things to Compare</h3><ol><li>As a baseline, the first measurement is sans Docker. This is just running the <em>hello.sh</em> script directly.</li><li>The second measure is just <em>docker run IMAGE</em>.</li><li>The third measure adds the “rm” flag to remove the container after execution.</li><li>The final one is to use <em>docker start </em>instead of <em>run</em>, so we can see the effect of reusing an already created container.</li></ol><h3>Docker for Mac</h3><p>Server Version: 1.12.2-rc1</p><pre>Running: ./hello.sh<br>avg: 5.897752ms<br>Running: docker run treeder/hello:sh<br>avg: 988.098391ms<br>Running: docker run — rm treeder/hello:sh<br>avg: 999.637832ms<br>Running: docker start -a reuse<br>avg: 986.875089ms</pre><p>(Note: looks like using Ubuntu as a base image is slightly faster than Alpine, in the 10–50ms range).</p><h3>Docker on Ubuntu</h3><p>Server Version: 1.12.1</p><pre>Running: ./hello.sh<br>avg: 2.139666ms<br>Running: docker run treeder/hello:sh<br>avg: 391.171656ms<br>Running: docker run — rm treeder/hello:sh<br>avg: 396.385453ms<br>Running: docker start -a reuse<br>each: 340.793602ms</pre><h3>Results</h3><p>As you can see from the results above, using Docker adds nearly a full second to the execution time of our script on Mac and ~390ms on Linux (~175x slower than running the script without Docker).</p><p>Now this may not be much of an issue if your script/application runs for a long period of time, but it is certainly an issue if you run short lived programs.</p><h3>Try it yourself</h3><p>Feel free to try running the script on your system and share the results! You can find everything you need here: <a href="https://github.com/treeder/dockers/tree/master/hello">https://github.com/treeder/dockers/tree/master/hello</a></p><p>Just clone that repo, cd into the hello directory and run:</p><pre>go run time.go</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2f06d47c9f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/travis-on-docker/the-overhead-of-docker-run-f2f06d47c9f3">The Overhead of Docker Run</a> was originally published in <a href="https://medium.com/travis-on-docker">Travis on Docker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Dockerize your Go (golang) App]]></title>
            <link>https://medium.com/travis-on-docker/how-to-dockerize-your-go-golang-app-542af15c27a2?source=rss----74c8ebbb9390---4</link>
            <guid isPermaLink="false">https://medium.com/p/542af15c27a2</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Travis Reeder]]></dc:creator>
            <pubDate>Tue, 20 Sep 2016 02:58:58 GMT</pubDate>
            <atom:updated>2016-09-20T02:58:57.709Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CO20-3P183ZAqrsJlF7n_A.png" /><figcaption>Golang on Docker</figcaption></figure><p>Turning your apps into a Docker image is a great way to distribute and deploy your applications. I won’t get into why to use Docker, but I will show you the easiest way to Dockerize your apps. This is the second of many of these I will do for various languages.</p><p>There are two ways to do this, one is arguably easier, but you end up with a bigger image than you need. The other has an extra step, but you end up with a much smaller image. The choice is yours (I prefer the latter though).</p><h3>Start with the app</h3><p>Here’s a simple Hello World app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/134b1fc770cd407b6e05869e8951e3b9/href">https://medium.com/media/134b1fc770cd407b6e05869e8951e3b9/href</a></iframe><p>It has a single external dependency, <a href="http://www.gorillatoolkit.org/pkg/mux">gorilla/mux</a>. Go doesn’t have a dependency management tool built in so we’ll briefly cover it here. If you have a dependency tool that you like, go ahead and use it. If you don’t, just run the following two commands:</p><pre>docker run --rm -it -v $PWD:/go/src/github.com/treeder/dockergo -w /go/src/github.com/treeder/dockergo treeder/glide init<br># Say No to the question it asks, then:<br>docker run --rm -it -v $PWD:/go/src/github.com/treeder/dockergo -w /go/src/github.com/treeder/dockergo treeder/glide update</pre><p>Now you’ll have your dependencies in the <em>/vendor</em> directory, which is where the go tools will look for dependencies. Those commands will work as is in any directory, but as you start to build our your code, you’ll want to replace <em>treeder/dockergo</em> with the name of your repository.</p><h3>Way 1: Build Inside your Dockerfile</h3><p>This first way is the more traditional Docker way where we do the complete build instructions in the Dockerfile. but it’s really not the best way as it will create a bloated image where most of the extra size is not needed.</p><p>Copy the following into a file called <em>Dockerfile</em>.</p><pre># iron/go:dev is the alpine image with the go tools added<br>FROM iron/go:dev</pre><pre>WORKDIR /app</pre><pre># Set an env var that matches your github repo name, replace treeder/dockergo here with your repo name<br>ENV SRC_DIR=/go/src/github.com/treeder/dockergo/<br># Add the source code:<br>ADD . $SRC_DIR<br># Build it:<br>RUN cd $SRC_DIR; go build -o myapp; cp myapp /app/</pre><pre>ENTRYPOINT [&quot;./myapp&quot;]</pre><p>Now let’s build it:</p><pre>docker build -t treeder/dockergo .</pre><p>And now we can run it and test it:</p><pre>docker run --rm -p 8080:8080 treeder/dockergo</pre><p>Surf to <a href="http://localhost:8080/">http://localhost:8080/</a> to see it running.</p><h3>Way 2: Build Outside your Dockerfile</h3><p>This requires one extra step, but it’s worth it, it will <strong>save you hundreds of MB</strong>. The trick is to build first, then just add resulting binary to a small base image via your Dockerfile.</p><p>Run the following command to build:</p><pre>docker run --rm -v &quot;$PWD&quot;:/go/src/github.com/treeder/dockergo -w /go/src/github.com/treeder/dockergo iron/go:dev go build -o myapp<br>docker build -t $USERNAME/$IMAGE:latest .</pre><p>Now the built binary called <em>myapp </em>will be in your current directory.</p><p>Copy over your <em>Dockerfile </em>with this now:</p><pre># iron/go is the alpine image with only ca-certificates added<br>FROM iron/go</pre><pre>WORKDIR /app</pre><pre># Now just add the binary<br>ADD myapp /app/</pre><pre>ENTRYPOINT [&quot;./myapp&quot;]</pre><p>Now let’s build it:</p><pre>docker build -t treeder/dockergo .</pre><p>And run it and test it:</p><pre>docker run --rm -p 8080:8080 treeder/dockergo</pre><p>Surf to <a href="http://localhost:8080/">http://localhost:8080/</a> to see it running.</p><h3>Multiple Ways to Skin an Image</h3><p>As you can see, we built our image two different ways with the exact same program inside. But one way is better than the other due to ending with a much smaller image. How much smaller? ~300 MB smaller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*ajYyI-A27VtUqRlkAfrhnw.png" /></figure><p>I’d say that’s worth it.</p><h3>Now What?</h3><p>Ok, so you turned your app into a Docker image, now what?</p><p>Well the next thing you’ll probably want to do is push it to a Docker Registry. <a href="https://hub.docker.com/">Docker Hub</a> is the default so try that first.</p><pre>docker push YOUR_USERNAME/dockergo</pre><p>Now go ask a friend to try your app by running this command:</p><pre>docker run --rm -it -p 8080:8080 YOUR_USERNAME/dockergo</pre><p>If your your friend can run your app that easily, you can also deploy software to your servers just as easily. All your friend and your servers need are Docker installed… which is a beautiful thing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=542af15c27a2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/travis-on-docker/how-to-dockerize-your-go-golang-app-542af15c27a2">How to Dockerize your Go (golang) App</a> was originally published in <a href="https://medium.com/travis-on-docker">Travis on Docker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Dockerize your Ruby on Rails App]]></title>
            <link>https://medium.com/travis-on-docker/how-to-dockerize-your-ruby-on-rails-app-690b516cd872?source=rss----74c8ebbb9390---4</link>
            <guid isPermaLink="false">https://medium.com/p/690b516cd872</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Travis Reeder]]></dc:creator>
            <pubDate>Tue, 30 Aug 2016 04:03:47 GMT</pubDate>
            <atom:updated>2016-09-20T12:17:07.135Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6R-gznIuGYiwHA8nMEfCQg.jpeg" /><figcaption>Rails on Docker</figcaption></figure><p>Turning your apps into a Docker image is a great way to distribute and deploy your applications. I won’t get into why to use Docker, but I will show you the easiest way to Dockerize your app. This is the first of many of these that I will do for various languages and frameworks.</p><p>Following along with the <a href="http://guides.rubyonrails.org/getting_started.html">Rails getting started guide</a>, let’s create a new application. This assumes you have Ruby installed.</p><pre># Get latest rails<br>gem install rails<br># Create an application<br>rails new blog<br># Now start it up to ensure it&#39;s working<br>cd blog<br>bin/rails server</pre><p>Now surf to <a href="http://localhost:3000/">http://localhost:3000/</a> and you’ll see the “Yay! You’re on Rails!” page.</p><h3>Let’s Dockerize It!</h3><p>Alright, we’ve got an app, let’s make a Docker image for it. There are a couple Gemfile changes you need to make in order for this to work properly. There are minor changes that won’t affect your normal workflow.</p><h4>1. Modify Gemfile</h4><pre># Add a couple gems:<br>gem &#39;json&#39;<br>gem &#39;bigdecimal&#39;</pre><pre># Change tzinfo-data gem from this: gem &#39;tzinfo-data&#39;, platforms: [:mingw, :mswin, :x64_mingw, :jruby], to this:<br>gem &#39;tzinfo-data&#39;</pre><p>Now update your bundle to get the changes:</p><pre>bundle update</pre><h4>2. Create a Dockerfile</h4><p>Create a file called <em>Dockerfile </em>and put the following in it:</p><pre>FROM iron/ruby:dev </pre><pre>RUN apk update &amp;&amp; apk upgrade <br>RUN apk add nodejs # Yes, Rails requires node... ¯\_(ツ)_/¯<br>WORKDIR /app</pre><pre>ADD Gemfile* /app/<br>RUN bundle install <br>ADD . /app/ </pre><pre>ENTRYPOINT [&quot;bin/rails&quot;]</pre><p>You can use this same <em>Dockerfile</em> for all your Rails apps.</p><h4>3. Build it:</h4><p>Run the following command to build your Docker image using the Dockerfile above.</p><pre>docker build -t treeder/rails-blog .</pre><p>Note: treeder above is my Docker Hub username, you should change that to yours if you want to push it to Docker Hub.</p><h4>4. Now Run It</h4><p>Now that we have our image, let’s run it!</p><pre>docker run --rm -it -p 3000:3000 -e &quot;PORT=3000&quot; treeder/rails-blog</pre><p>And again, surf to <a href="http://localhost:3000/">http://localhost:3000/</a> to see it running.</p><h3>Now What?</h3><p>Ok, so you turned your app into a Docker image, now what?</p><p>Well the next thing you’ll probably want to do is push it to a Docker Registry. <a href="https://hub.docker.com/">Docker Hub</a> is the default so try that first.</p><pre>docker push YOUR_USERNAME/rails-blog</pre><p>Then go ask a friend to try your app by running this command:</p><pre>docker run --rm -it -p 3000:3000 -e &quot;PORT=3000&quot; YOUR_USERNAME/rails-blog</pre><p>If your your friend can run your app that easily, you can also deploy software to your servers just as easily. All your friend and your servers need are Docker installed… which is a beautiful thing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=690b516cd872" width="1" height="1" alt=""><hr><p><a href="https://medium.com/travis-on-docker/how-to-dockerize-your-ruby-on-rails-app-690b516cd872">How to Dockerize your Ruby on Rails App</a> was originally published in <a href="https://medium.com/travis-on-docker">Travis on Docker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>