Skip to content

Instantly share code, notes, and snippets.

@bruceherve
Last active November 22, 2022 15:48
Show Gist options
  • Save bruceherve/ad694117e1f897dce675c010933f44a3 to your computer and use it in GitHub Desktop.
Save bruceherve/ad694117e1f897dce675c010933f44a3 to your computer and use it in GitHub Desktop.
My multi stage Dockerfile for Go Lang Applications
# syntax=docker/dockerfile:1
# specify base image
FROM golang:1.19.3-alpine as build
# enable Go Modules
ENV GO111MODULE=on
# create working directory inside the image
WORKDIR /app
# copy Go modules and dependencies to image
COPY ./go.mod .
COPY ./go.sum .
# download Go modules and dependencies
RUN go mod download
# copy directory files i.e all files ending with .go
COPY . .
# compile application
RUN CGO_ENABLED=0 go build -o main .
FROM golang:1.19.3-alpine
WORKDIR /app
COPY --from=build /app/main ./
# tells Docker that the container listens on specified network ports at runtime
EXPOSE 8080
CMD [ "./main" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment