Thanks Laurel

The Easiest Way to Develop with Go — Introducing a Docker Based Go Tool

Travis Reeder
Aug 28, 2015 · 3 min read

UPDATE Oct. 28, 2015: Made a follow on project that takes this and makes it bigger/better and better. See here.

While trying to make a drop dead simple example for running Go programs on IronWorker, I realized there’s just no simple way to for us to point someone at an example repo with Go code and have them up and running in a few minutes. This can be done in other languages fairly easily because they don’t have special requirements like a GOPATH, a specific directory structure, and they typically have easier dependency management.

Is there a better way?

I’ve been thinking and writing a lot about Docker lately, and using it in almost everything I do (yes, I have a Docker man crush). Mostly because at Iron.io, we run containers… lot’s of containers. In doing that, I’ve come to realize how insanely powerful Docker can be. It’s not just hype, trust me.

We’ve been showing people how to build and test their Go programs inside Docker containers for a while now, but it’s always been a pain. Putting your code in specific places, setting up a GOPATH, using a tool like godep to vendor dependencies (which has its own requirements like your code must be in version control), mounting directories properly, etc. It can work, but it’s not pretty.

Well, today it just got prettier.

Introducing the Docker Go tool

I’ve created a Docker based Go tool, `treeder/go`, that makes developing in Go uber easy. The only thing you need to have installed is Docker. Here are some of the features and benefits:

Demo

The Basics

Let’s try the basics. First, copy and paste the following program into a file named app.go, in any directory.

Notice it has a dependency? Let’s vendor it:

That will put the dependencies in a /vendor directory.

Now let’s build it:

And run it:

Check http://localhost:8080/ . Boom. We ran that in the iron/base image which is a really small image that has everything needed to run your Go program.

More Cool Stuff

How about we build a runnable Docker image containing our program:

Now run your fresh new image:

Check http://localhost:8080/ again. Boom again. And better yet, the image should be tiny. Run `docker images` to check how big it is, should be about ~12MB total.

Or build a remote repo:

You’ll end up with a binary for that remote repository in the directory where you run that command.

Conclusion

Docker for development wins again. If you’ve developed in Go before, you should probably appreciate the simplicity here. This is still pretty experimental and doesn’t implement a lot of the tool chain yet, but from what I know, this is probably the easiest way to get started with Go. Using this, you can point someone at a repo and they can clone, build and run without any setup other than Docker.

Full documentation and source code for the project is here: https://github.com/treeder/go

I’d love your feedback! Create a Github issue or comment here.

Iron.io Technical Blog

The place where we post all the good techie stuff.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store