Last active
March 13, 2019 20:00
-
-
Save rhymes/55c9a587afbabf1886a71c07c5364193 to your computer and use it in GitHub Desktop.
Sample docker multistage file with Go
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:alpine AS builder | |
# install packages | |
RUN apk add --no-cache curl git | |
# https://golang.github.io/dep/docs/FAQ.html#how-do-i-use-dep-with-docker | |
RUN curl -fsSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 && chmod +x /usr/local/bin/dep | |
RUN mkdir -p $APP_PATH | |
WORKDIR $APP_PATH | |
COPY Gopkg.toml Gopkg.lock ./ | |
RUN dep ensure -vendor-only | |
# add the code and compile it into a static binary | |
ADD . ./ | |
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /app . | |
# use multistage to copy the binary from the builder stage to a scratch image | |
FROM scratch | |
COPY --from=builder /app ./ | |
ENTRYPOINT ["./app"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment