Problem Statement
What is the purpose of a multi-stage build in Dockerfile?
Explanation
Multi-stage builds use multiple FROM statements in a Dockerfile. You build in one stage (with build tools) and then copy only the runtime artifacts into a slim final image. This reduces size, surface-area for vulnerabilities, and improves performance.
Code Solution
SolutionRead Only
FROM golang:1.20 AS builder WORKDIR /app COPY . . RUN go build -o myapp FROM alpine:latest WORKDIR /app COPY --from=builder /app/myapp . CMD ["./myapp"]
Practice Sets
This question appears in the following practice sets:
