Skip to content

Instantly share code, notes, and snippets.

@rhymes
Last active March 13, 2019 20:00
Show Gist options
  • Save rhymes/55c9a587afbabf1886a71c07c5364193 to your computer and use it in GitHub Desktop.
Save rhymes/55c9a587afbabf1886a71c07c5364193 to your computer and use it in GitHub Desktop.
Sample docker multistage file with Go
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