hardMultiple ChoiceObjective-mapped
XK0-006 Practice Question: A developer writes a Dockerfile that installs…
A developer writes a Dockerfile that installs multiple packages. To reduce the final image size, which of the following practices is most effective?
⚠ Common exam trap
CompTIA often tests the misconception that using a minimal base image or cleaning up in separate steps is sufficient, when in fact the layer persistence model means only combining RUN commands (and cleaning within the same layer) truly eliminates intermediate file bloat.
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
✓
Combine multiple RUN commands into a single RUN instruction.
Combining multiple RUN commands into a single RUN instruction reduces the number of layers created in the Docker image. Each RUN instruction creates a new layer, and by merging them, you avoid storing intermediate files (e.g., package cache) across separate layers, which significantly shrinks the final image size. This is a direct and effective method for minimizing image footprint when installing multiple packages.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use a multi-stage build.
Why it's wrong here
Multi-stage is effective but not directly about combining RUN commands.
- ✓
Combine multiple RUN commands into a single RUN instruction.
Why this is correct
Reduces number of layers, decreasing image size.
- ✗
Use apt-get clean after each installation.
Why it's wrong here
Only cleans cache, doesn't reduce layers.
- ✗
Use a minimal base image like alpine.
Why it's wrong here
Good practice but not about combining instructions.
Go deeper
Related to this question
About these practice questions
One of 979 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.