KCSA practice question 3 of 15

What is a multi-stage build?

Full set: 59 questions
Answer options
A: A build process that involves multiple developers collaborating on building an image.
B: A build process that involves multiple repositories for storing container images.
C: A build process that involves multiple containers running simultaneously to speed up the image creation.
D: A build process that involves multiple stages of image creation, allowing for smaller, optimized images. Correct answer
Correct Answer:
D. A build process that involves multiple stages of image creation, allowing for smaller, optimized images.
Explanation

A multi-stage build is a feature used in Dockerfiles to create more efficient and smaller container images. It involves using multiple FROM instructions, where each FROM starts a new, temporary build stage. An initial stage might use a larger image containing compilers, SDKs, and build tools to compile the application. A subsequent, final stage then starts from a minimal base image (e.g., alpine or distroless) and copies only the necessary compiled artifacts from the initial stage. This process discards all intermediate build tools and dependencies, resulting in a significantly smaller, optimized, and more secure production image.

Why Incorrect

A. This describes a collaborative development workflow, not the technical process of a multi-stage build.
B. This refers to the architecture of a container registry or image distribution strategy, not the image creation process.
C. This describes parallelization, whereas multi-stage builds are about sequential stages to isolate build-time and run-time environments.

References

1. Docker Official Documentation, "Multi-stage builds": "With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don’t want in the final image."

2. Red Hat OpenShift Documentation, "Creating images using a multi-stage build": "A multi-stage build is a process that divides the Dockerfile into multiple stages to separate the build-time dependencies from the run-time dependencies... The final image is smaller and more secure because it does not contain the build-time dependencies." (Section: "About multi-stage builds").

3. Google Cloud Documentation, "Container build best practices": "One of the most effective ways to minimize your image size is to use Docker's multi-stage builds. For example, you can use a build stage that contains the build tools for your application, and a separate runtime stage that contains only the application runtime and the built application." (Section: "Minimize image size").

Scroll to Top