FROM golang
ENV CGO_ENABLED=0
ENV GO111MODULE=on
WORKDIR /go/src/flog
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN go build -o /bin/flog
FROM scratch
COPY --from=0 /bin/flog /bin/flog
ENTRYPOINT ["flog"]
But we can build binary file directly like this:
FROM golang
ENV CGO_ENABLED=0
ENV GO111MODULE=on
WORKDIR /go/src/flog
COPY . ./
RUN go build -ldflags="-w -s" -o /bin/flog
FROM scratch
COPY --from=0 /bin/flog /bin/flog
ENTRYPOINT ["flog"]
Is there any problem to build binary file directly? I know it's not essential or critical point, but I want to make it simpler. Thanks for reading.
Pre-downloading the modules makes the image layer with Go module caches. With the module cache, we don't have to re-download the modules if there are no module changes, then we can only build source code.
Current Dockerfile:
But we can build binary file directly like this:
Is there any problem to build binary file directly? I know it's not essential or critical point, but I want to make it simpler. Thanks for reading.