Created
November 19, 2019 14:23
-
-
Save billglover/21894bb66f05c320b898863bf012371c to your computer and use it in GitHub Desktop.
A minimal Dockerfile for Go applications
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:alpine as build | |
RUN apk add --update --no-cache ca-certificates git | |
RUN adduser -D -g '' appuser | |
RUN mkdir /src | |
WORKDIR /src | |
COPY . . | |
RUN go mod download | |
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o /app | |
FROM scratch | |
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | |
COPY --from=build /app /app | |
COPY --from=build /etc/passwd /etc/passwd | |
USER appuser | |
EXPOSE 8080 | |
ENTRYPOINT ["/app"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment