DCA · Question #33
What is the purpose of multi-stage builds?
The correct answer is B. Optimizing images by copying artifacts selectively from previous stages. Multi-stage builds are primarily used to optimize Docker images by reducing their size and attack surface.
Question
What is the purpose of multi-stage builds?
Options
- ABetter logical separation of Dockerfile instructions for better readability
- BOptimizing images by copying artifacts selectively from previous stages
- CBetter caching when building Docker images
- DFaster image builds by allowing parallel execution of Docker builds
How the community answered
(33 responses)- A6% (2)
- B91% (30)
- D3% (1)
Why each option
Multi-stage builds are primarily used to optimize Docker images by reducing their size and attack surface.
While multi-stage builds can improve the logical organization of a Dockerfile, their main purpose is not just readability but concrete image optimization.
Multi-stage builds optimize images by allowing the separation of build-time dependencies from runtime dependencies. Only the necessary artifacts, such as compiled binaries, are copied from an earlier build stage to the final production image, discarding build tools and intermediate files and significantly reducing the final image size.
Although caching is leveraged during multi-stage builds, it's a general Docker build feature; the primary purpose of multi-stage builds is not better caching, but image size reduction through artifact selection.
Multi-stage builds execute stages sequentially; they do not inherently allow for parallel execution of Docker builds, which would typically require separate build processes.
Concept tested: Docker multi-stage builds for image optimization
Source: https://docs.docker.com/build/building/multi-stage/
Topics
Community Discussion
No community discussion yet for this question.