Last active
November 22, 2022 15:48
-
-
Save bruceherve/ad694117e1f897dce675c010933f44a3 to your computer and use it in GitHub Desktop.
My multi stage Dockerfile for Go Lang Applications
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
# 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