Skip to content

Instantly share code, notes, and snippets.

@jbergstroem
Last active September 29, 2017 10:35
Show Gist options
  • Save jbergstroem/680cb7db6f90319dcd7666f30e9b1ec4 to your computer and use it in GitHub Desktop.
Save jbergstroem/680cb7db6f90319dcd7666f30e9b1ec4 to your computer and use it in GitHub Desktop.
Dockerfile example of a small (<5mb) statically built go binary
FROM golang:1.9-alpine3.6 as builder
MAINTAINER Johan Bergström <foo@bar.com>
COPY . /go/src/github.com/jbergstroem/secret-repo
RUN \
echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/community" \
>> /etc/apk/repositories && \
apk update && \
apk add git glide upx@edge && \
cd /go/src/github.com/jbergstroem/secret-repo && \
glide install && \
go build release -ldflags '-d' -tags 'release netgo' -installsuffix netgo \
-a -o secret-binary . && \
upx --coff --brute --no-progress secret-binary
# copy results into new image
FROM scratch
MAINTAINER Johan Bergström <foo@bar.com>
COPY --from=builder /go/src/github.com/jbergstroem/secret-repo/secret-binary /
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY config.yaml /
EXPOSE 3000
ENTRYPOINT ["/secret-binary"]
CMD ["start"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment