March 2021
Intermediate to advanced
260 pages
5h 45m
English
Create a Dockerfile with this code:
| | FROM golang:1.14-alpine AS build |
| | WORKDIR /go/src/proglog |
| | COPY . . |
| | RUN CGO_ENABLED=0 go build -o /go/bin/proglog ./cmd/proglog |
| | |
| | FROM scratch |
| | COPY --from=build /go/bin/proglog /bin/proglog |
| | ENTRYPOINT ["/bin/proglog"] |
Our Dockerfile uses multistage builds: one stage builds our service and one stage runs it. This makes our Dockerfile easy to read and maintain while keeping our build efficient and the image small.
The build stage uses the golang:1.14-alpine image because we need the Go compiler, our dependencies, and perhaps various system libraries. These take up disk space, and we don’t need them after we have compiled our binary. In the second stage, ...
Read now
Unlock full access