Skip to content

Instantly share code, notes, and snippets.

@kanzitelli
Created September 12, 2019 16:48
Show Gist options
  • Save kanzitelli/8c510709e12ab92fb660b572384c6c7b to your computer and use it in GitHub Desktop.
Save kanzitelli/8c510709e12ab92fb660b572384c6c7b to your computer and use it in GitHub Desktop.
Dockerfile for Golang projects
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