Created
September 12, 2019 16:48
-
-
Save kanzitelli/8c510709e12ab92fb660b572384c6c7b to your computer and use it in GitHub Desktop.
Dockerfile for Golang projects
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
ARG GO_VERSION=1.12 | |
FROM golang:${GO_VERSION}-alpine AS builder | |
RUN apk add --no-cache ca-certificates git tzdata | |
WORKDIR /src | |
COPY ./go.mod ./go.sum ./ | |
RUN go mod download | |
COPY ./ ./ | |
# copying images files to the root | |
COPY ./images /images | |
RUN CGO_ENABLED=0 go build \ | |
-installsuffix 'static' \ | |
-o /app . | |
# FINAL CONTAINER | |
FROM scratch AS final | |
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo | |
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | |
COPY --from=builder /app /app | |
# so our images are available in the final container | |
COPY --from=builder /images /images | |
EXPOSE 80 | |
ENTRYPOINT ["/app"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment