Menu

Golang and Docker 1.13 on your Raspberry Pi

This post is a quick for getting a Golang development environment set up on your Raspberry Pi with Docker 1.13.

Golang is a compiled language which has many advantages on the Raspberry Pi over slower interpreted languages. Since many popular projects now build their solutions in Go it opens up a wide range of cool projects to the Pi.

Getting Docker 1.13

Docker is a single command away: curl -sSL https://get.docker.com | sh. The default storage driver is overlay (shown on docker info). This is the output of docker version:

If you want to turn on experimental mode then edit the ExecStart command in /etc/systemd/system/docker.service.d/overlay.conf adding --experimental=true. Note that this is not the usual location of your Docker systemd file, the RPi has an additional drop-in file.

The cool bit about enabling experimental mode is that you can play with bleeding edge features such as Prometheus metrics.

Warned - the Docker team told the Captains that experimental features are likely to have breaking changes, so don't get too attached to their interfaces.

Getting Go

There are three ways popular to get Golang on Raspbian:

Method 1 - Raspbian repository

This is the simplest method but is likely to be very out of date. I installed Golang with apt-get install golang and it came out at a very early version:

$ go version
go1.3.3 linux/arm`

The Go team have made great strides to improve the execution of Go on ARM devices, so you should really to keep up to date to get the most out of your experience.

Method 2 - Get binary from Golang.org

This is a very manual installation method, but one of the quickest and is also suitable for installing and upgrading Node.js. Both projects provide pre-built binaries.

Head over to http://golang.org/dl/ and pick go1.7.5.linux-armv6l.tar.gz or whatever is newer with armv6l in the name. This is the architecture of the original Raspberry Pi meaning it will work on all models.

The Docker method means you don't have to install any binaries onto your system directly. In fact you can even run multiple versions of Go at the same time. This is a huge plus-point for Docker and helps solve the problem of outdated repositories.

Unfortunately the Docker Hub has no automated builds for ARM images, so use an image from a trusted source or build your own.

I was able to adapt the Golang official Dockerfile for ARM which uses Alpine Linux as a base image, this means you get a much smaller working image than with an Ubuntu or Debian base.