Last active
February 25, 2023 06:29
-
-
Save monirz/145f5037e650faf1a7855a53ce325749 to your computer and use it in GitHub Desktop.
Golang Dockerfile multi stage build
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
# Build stage | |
FROM golang:1.19.3-alpine AS build | |
ENV CGO_ENABLED=0 | |
ENV GO111MODULE=on | |
WORKDIR /app | |
COPY go.mod . | |
COPY go.sum . | |
RUN go mod download | |
COPY . . | |
RUN go build -o /server | |
# Final stage | |
FROM alpine:latest | |
RUN apk --no-cache add ca-certificates | |
WORKDIR /root/ | |
COPY --from=build /server . | |
ENV PORT=8090 | |
EXPOSE $PORT | |
CMD ["./server"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment