My Go IDE in a Container

I’m a Java developer and I like to use an IDE. Specifically, when I write code, I like to have syntax highlighting, autocompletion/suggestions, and access to developer documentation.

Eclipse IDE for Java — Autocompletion and Documentation

I also started learning to write Go. I’ve written a few things in Go because I like its ability to compile into native code. One utility I wrote was a command line OAuth 2.0 utility that lets you generate offline refresh tokens, and most recently, a Go program that calculates digits of Pi using the Chudnovsky method with Binary Splitting.

Initially, I wrote Go in Vi with no language support at all. But I thought it’d be nice to get some of the features I’m accustomed to as a Java developer. I ended up finding a plugin called Vim-Go. It looks like everything I wanted, except it was not easy to install:

  • It needed several other plugins to work
  • Some plugins needed features that aren’t in my Vim installation, such as python2 support
  • It needed a number of Go utilities to work, such as goimport, godef, and golint, among others
  • It did not include other components that you may want to have too, like NERDTree

As I was setting up Vim-Go, I was a little concerned about installing a bunch of plugins and components on my laptop that I would later need to re-install if I moved to another environment. (As a Java developer, I have installed the Eclipse IDE countless times with countless plugins, many times as a result of having switched computers.) Rather than toiling through a similar process with my Vim-based IDE, I thought maybe I could build the entire thing in a container image.

There are a several benefits to using a container for this:

  1. The installation instructions are self-documenting — the Dockerfile has the exact steps I need to install the IDE environment.
  2. I don’t need to install local packages/dependencies — I’ll just install them in the Docker image!
  3. I can run it anywhere — It doesn’t matter what environment I’m using, I can fire up `docker run -ti saturnism/go-ide` and it’ll drop me into an environment I’m familiar with.
  4. It’s customizable — Don’t like what’s in the container? Customize it in the Dockerfile, and someone else can use it too.
  5. I can install native library dependencies in the container instead of my laptop.

In a nutshell, I built a container image that installs and configures:

You can try out the IDE by running:

docker run --rm -ti saturnism/go-ide

Note: All your files will be deleted once you leave the container! Oh no. No one would like to lose their work. Here are two techniques that you can use to make sure your work is saved!

You can mount a volume to store your files:

docker run --rm -ti -v /mysource:/go/src

Alternatively, you can save your file in a persisted container volume:

docker create -v /go/src --name myproject saturnism/go-ide /bin/true
docker run -d --volumes-from myproject saturnism/go-ide

This works perfectly fine with Docker Machine as well. If you haven’t read my previous articles, I’ve been using Docker Machine on Google Cloud Platform for many months now — and I have plenty of tips and tricks to share on that subject too.

Update: Sure enough, I had to switch my work laptop shortly after I containerized my Go IDE. I sure was happy I did it!

Update: You can also mount $GOPATH to /go, but you will need to run :GoInstallBinaries in Vi manually. There is also an Atom container named atocker! See the Reddit thread.

Like the idea? Find the source on GitHub under saturnism/go-ide and customize it a bit more to fit your specific Go development preferences!



A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

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