Skip to content

Instantly share code, notes, and snippets.

@monirz
Last active February 25, 2023 06:29
Show Gist options
  • Save monirz/145f5037e650faf1a7855a53ce325749 to your computer and use it in GitHub Desktop.
Save monirz/145f5037e650faf1a7855a53ce325749 to your computer and use it in GitHub Desktop.
Golang Dockerfile multi stage build
# 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