Skip to content

Instantly share code, notes, and snippets.

@samuelb
Last active February 8, 2022 20:46
Show Gist options
  • Save samuelb/92faefb9169e1df79a8b27293aa43822 to your computer and use it in GitHub Desktop.
Save samuelb/92faefb9169e1df79a8b27293aa43822 to your computer and use it in GitHub Desktop.
Build static linked golang programm and put it into an empty docker container
FROM golang:1.17 as builder
WORKDIR /go/src/app
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY main.go .
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "-w -s" -o app
FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /go/src/app/app .
CMD ["./app"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment