;

Nabeel Sulieman

Easier than Expected: Raspberry Pi Docker Images

2020-06-17

A few days ago I received a request from someone who wanted to run k8s-ecr-login-renew on a Raspberry Pi Kubernetes cluster. Fortunately, I already had experience building Go apps for that architecture. But what I really had no clue about was the next step: putting that executable into a Docker image.

Looking around online, I found a few articles that recommended installing an experimental version of Docker, and then running the docker buildx... command to build for different platforms. I also found that the Alpine image in Docker Hub has published ARM-based versions. I don't know why, but I decided to just try building an image without installing the experimental feature. I'm happy I did that, because it turned out to be quite easy to build. Here's how I did it:

  • Start with a regular (x86) image for building the Go app
  • Set environment variables for Go to build for the ARM processor
  • Build the Go app for ARM: RUN env GOOS=linux GOARCH=arm GOARM=5 go build...
  • Switch to an ARM-based Alpine linux image: arm32v7/alpine
  • Copy the executable from the build image to the Alpine image

You can see this all in action in the Dockerfile-arm file in the project repo.

And that is it, super easy!