Created
September 14, 2021 16:15
-
-
Save henryhamon/848d4e341a4d12891b7511b43e7a5dd9 to your computer and use it in GitHub Desktop.
Golang Docker file
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
FROM golang:1.16.7-alpine AS builder | |
# git is needed to download those packages | |
# use this if u called to any https service | |
RUN apk --update add --no-cache ca-certificates openssl git && update-ca-certificates | |
# without ssl | |
RUN apk --update add --no-cache git | |
WORKDIR /app | |
copy go.mod ./ | |
copy go.sum ./ | |
RUN go mod download | |
COPY . . | |
# build as binary file | |
RUN GO111MODULE="on" CGO_ENABLED=0 GOOS=linux go build -o ./<service-name> ./ | |
FROM scratch | |
# ignore this if you don't need ssl | |
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | |
WORKDIR /app | |
# copy the built binary file | |
COPY --from=builder /app/<service-name> /<service-name> | |
EXPOSE 8080 | |
CMD [ "/<service-name>" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment