Totally static Go builds

Written by Will Rouesnel

I wouldn‘t make a post on my blog just so I don’t have to keep googling something would I? Of course I would. It's like…95% of the reason I keep this.

Totally static go builds - these are great for running in Docker containers. The important part is the command line to create them - it‘s varied a bit, but the most thorough I’ve found is this (see this Github Issue):

CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' .

This will create an “as static as possible” binary - beware linking in things which want glibc, since pluggable name resolvers will be a problem (which you can workaround in Docker quite well, but that's another question).