hardMultiple Choice
XK0-006 Practice Question: A DevOps engineer wants to reduce the size of a…
A DevOps engineer wants to reduce the size of a Docker image by combining build stages. Which Dockerfile feature should be used?
⚠ Common exam trap
A common mix-up: candidates confuse layer caching (a performance feature) with multi-stage builds (a size-reduction feature), or they assume using a smaller base image alone achieves the same result as eliminating entire build stages.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Multi-stage builds (multiple FROM statements)
Multi-stage builds, implemented by using multiple FROM statements in a single Dockerfile, allow a DevOps engineer to copy only the necessary artifacts from intermediate build stages into the final image. This eliminates build-time dependencies, tools, and intermediate layers from the final image, significantly reducing its size without sacrificing build functionality.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
RUN --mount=type=cache
Why it's wrong here
A cache mount speeds up repeated package downloads by persisting build cache between builds; it does not merge stages or shrink the final image. Multi-stage builds with a single final stage are what combine stages. Cache mounts suit iterative local builds where dependency re-downloading dominates build time.
- ✗
Layer caching
Why it's wrong here
Layer caching reuses unchanged layers to accelerate rebuilds; it does not combine build stages or remove intermediate artefacts from the shipped image. Multi-stage builds are the mechanism that merges stages. Layer caching is the right answer when the goal is faster rebuilds, not a smaller final image.
- ✓
Multi-stage builds (multiple FROM statements)
Why this is correct
Multi-stage builds let later stages copy only required artefacts from earlier stages, discarding build tools, caches and intermediate layers. This directly reduces the final image size, meeting the DevOps engineer's goal of combining build stages rather than shipping a single bloated stage.
- ✗
Using a smaller base image like Alpine
Why it's wrong here
Swapping to Alpine changes the base image, not the build structure, so intermediate layers and artefacts still ship in the final image. It is tempting because Alpine images are small, and would be correct when the requirement is trimming runtime footprint rather than eliminating build-time dependencies.
About these practice questions
One of 781 original XK0-006 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This XK0-006 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the XK0-006 exam.