An application stage is the final stage in a multi-stage Dockerfile. It assembles the runtime image from a minimal base image, application files, configuration, and artifacts copied from a builder stage. section 4.4
A Go application stage typically:
- Uses a small runtime base such as diamol/base:2e instead of the Go toolset image. section 4.4
- Sets environment variables and a startup command for the application. section 4.4
- Copies static HTML from the host and the compiled server from the builder stage. section 4.4
- Marks the server executable with chmod on Linux; the command has no effect on Windows. section 4.4
Go runtime stage
FROM diamol/base:2e ENV IMAGE_API_URL="http:/./iotd/image" \ ACCESS_API_URL="http:/./accesslog/access-log" CMD ["/web/server"] WORKDIR web COPY index.html . COPY --from=builder /server . RUN chmod +x server section 4.4
Listing 4.4 Dockerfile for building a Go application from source
FROM diamol/golang:2e AS builder
COPY go.mod main.go /go/
RUN go build -o /server
# app
FROM diamol/base:2e
ENV IMAGE_API_URL="http:/./iotd/image" \
ACCESS_API_URL="http:/./accesslog/access-log"
CMD ["/web/server"]
WORKDIR web
COPY index.html .
COPY --from=builder /server .
RUN chmod +x server
Browse the complete Dockerfile, including the builder stage and the final application stage. section 4.4
