Minimal docker container with go lang app

25 May, 2017

I was trying to build a minimal docker container running a go process. My Dockerfile looks like this:

  FROM alpine
  ADD main /
  CMD ["/main"]

Building the container works fine but once I try to run it I get this error:

  standard_init_linux.go:178: exec user process caused "no such file or directory"

Turns out that to run go process in alpine you need to set CGO_ENABLED to 0

  CGO_ENABLED=0 go build -a -installsuffix cgo -o main .t

This is due to mismatch between glibc on my local machine and glibc in the alpine container (dont build production containers on your machine!). If you need CGO enabled you need to build the binaries within an alpine container. (Thanks to Johan Breandhorst for explaining this to me)