Skip to content

Instantly share code, notes, and snippets.

@max-weis
Created September 25, 2019 09:25
Show Gist options
  • Save max-weis/798a3fc15240784c0d810018ca2d6b20 to your computer and use it in GitHub Desktop.
Save max-weis/798a3fc15240784c0d810018ca2d6b20 to your computer and use it in GitHub Desktop.
Golang Multistage Dockerfile
# build stage
FROM golang:1.13-alpine as build
WORKDIR $GOPATH/app/
RUN apk add git
# copy and download dependencies
COPY go.* .
RUN go mod download
#compile app
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o main
#resulting app
FROM scratch as final
COPY --from=build go/app/main /app/
WORKDIR /app
EXPOSE 8080
ENTRYPOINT [ "./main" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment