Skip to content

Instantly share code, notes, and snippets.

@josectheone
Last active October 19, 2019 23:29
Show Gist options
  • Save josectheone/233590225cee247678a272eaf55f1427 to your computer and use it in GitHub Desktop.
Save josectheone/233590225cee247678a272eaf55f1427 to your computer and use it in GitHub Desktop.
Dockerfile - Golang com base Alpine
FROM golang:alpine AS builder
RUN apk update && apk add --no-cache git ca-certificates tzdata && update-ca-certificates
RUN adduser -D -g '' appuser
ENV GO111MODULE=on
WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN go get -d -v
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o /app/hello .
FROM scratch
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /go/hello /app/
USER appuser
EXPOSE 8080
ENTRYPOINT ["/app/hello"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment