Skip to content

Instantly share code, notes, and snippets.

@irwinby
Created July 8, 2022 16:55
Show Gist options
  • Save irwinby/1b3c0301fc9f51b788216195cb88a121 to your computer and use it in GitHub Desktop.
Save irwinby/1b3c0301fc9f51b788216195cb88a121 to your computer and use it in GitHub Desktop.
Dockerfile template for creating a Docker image for the Go application
FROM --platform=$BUILDPLATFORM golang:1.18-buster as builder
WORKDIR /go/src/github.com/{ORGANIZATION_NAME}/{REPOSITORY_NAME}
COPY go.* .
RUN go mod download
COPY . .
ARG TARGETOS TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o {BINARY_NAME} main.go
FROM alpine:3.16.0
RUN apk --no-cache add ca-certificates
COPY --from=builder /go/src/github.com/{ORGANIZATION_NAME}/{REPOSITORY_NAME} .
CMD [ "./{BINARY_NAME}" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment