Last active
July 27, 2023 10:18
-
-
Save nanmu42/90bf2d3870b64aec20b68ec3c104a610 to your computer and use it in GitHub Desktop.
Minimal-sized Golang Docker Image
This file contains hidden or 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-alpine as golang | |
RUN apk --no-cache add git zip tzdata ca-certificates | |
# avoid go path, use go mod | |
WORKDIR /app | |
COPY . . | |
RUN CGO_ENABLED=0 go build -ldflags "-s -w -extldflags "-static"" ./cmd/appnamehere | |
WORKDIR /usr/share/zoneinfo | |
# -0 means no compression. Needed because go's | |
# tz loader doesn't handle compressed data. | |
RUN zip -r -0 /zoneinfo.zip . | |
FROM scratch | |
# the timezone data: | |
ENV ZONEINFO /zoneinfo.zip | |
COPY --from=golang /zoneinfo.zip / | |
# the tls certificates: | |
COPY --from=golang /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | |
# Copy the binary | |
COPY --from=golang /app/appnamehere/ | |
# example ENV: COS secret ID and secret key | |
ENV COS_SECRET_ID="" COS_SECRET_KEY="" | |
# example EXPOSE | |
EXPOSE 3030 | |
ENTRYPOINT ["/appnamehere"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment