Last active
September 29, 2017 10:35
-
-
Save jbergstroem/680cb7db6f90319dcd7666f30e9b1ec4 to your computer and use it in GitHub Desktop.
Dockerfile example of a small (<5mb) statically built go binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.9-alpine3.6 as builder | |
MAINTAINER Johan Bergström <[email protected]> | |
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 <[email protected]> | |
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