Skip to content

Instantly share code, notes, and snippets.

@jasonkeene
Created March 6, 2019 00:10
Show Gist options
  • Save jasonkeene/c3291296c0c93bb741b0f2be8d92682d to your computer and use it in GitHub Desktop.
Save jasonkeene/c3291296c0c93bb741b0f2be8d92682d to your computer and use it in GitHub Desktop.
Go Modules Dockerfile
FROM golang:1.12 as builder
WORKDIR /root
ENV GOOS=linux \
GOARCH=amd64 \
CGO_ENABLED=0
COPY /go.mod /go.sum /root/
RUN go version && \
go mod download
COPY / /root/
RUN go build \
-a \
-installsuffix nocgo \
-o /your_program \
-mod=readonly \
your/package
FROM scratch
COPY --from=builder /your_program /srv/
WORKDIR /srv
CMD [ "/srv/your_program" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment