Last active
October 10, 2019 15:05
-
-
Save piotrpersona/d07ea82c856663f992964e5244101c7e to your computer and use it in GitHub Desktop.
Multistage Dockerfile for golang binaries
This file contains 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@sha256:2b3ca6f02d74eaf6f2d1788a16c1ccf551fe2407cb457636f3826f0108fed8ff AS stage-build | |
WORKDIR "/go/src/package" | |
RUN apk update && apk add dep git | |
COPY Gopkg.* ./ | |
RUN dep ensure --vendor-only | |
COPY main.go . | |
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \ | |
go build \ | |
-ldflags="-w -s" \ | |
-o /go/bin/package | |
FROM scratch | |
COPY --from=stage-build \ | |
/go/bin/package /usr/local/bin/package | |
ENTRYPOINT ["/usr/local/bin/package"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment