Skip to content

Instantly share code, notes, and snippets.

@billglover
Created November 19, 2019 14:23
Show Gist options
  • Save billglover/21894bb66f05c320b898863bf012371c to your computer and use it in GitHub Desktop.
Save billglover/21894bb66f05c320b898863bf012371c to your computer and use it in GitHub Desktop.
A minimal Dockerfile for Go applications
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