Skip to content

Instantly share code, notes, and snippets.

@endocrimes
Last active December 4, 2017 11:11
Show Gist options
  • Save endocrimes/a32d0f5ac5eca8173267855d22244b97 to your computer and use it in GitHub Desktop.
Save endocrimes/a32d0f5ac5eca8173267855d22244b97 to your computer and use it in GitHub Desktop.
Steps for distributing small Docker images for Go binaries

Distributing smol Docker images for Go binaries

Building a fully static go binary:

$ GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o build/linux-{{tool-name}} .

The Dockerfile

FROM scratch
MAINTAINER Danielle Tomlinson <dani@tomlinson.io>

# You'll need to update this to be wherever you keep your ca-certs.
ADD resources/ca-certificates.crt /etc/ssl/certs/

ADD build/linux-{{tool-name}} /{{tool-name}}
 
CMD ["/{{tool-name}}"]

This results in ~10mb images for your Golang binaries, rather than distributing a bunch of things you don't need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment