Question 77 of 510
Scripting, Containers and AutomationhardMultiple ChoiceObjective-mapped

Quick Answer

The correct answer is that the Dockerfile violates the best practice of combining `apt-get update` and `apt-get install` in a single RUN command. When these commands are separated, Docker caches the layer from `apt-get update`, meaning subsequent builds reuse a stale package index, which can lead to installing outdated or vulnerable packages. Combining them into one RUN command ensures the update and install happen atomically, guaranteeing a fresh package index and reducing overall image size by eliminating unnecessary intermediate layers. On the CompTIA Linux+ XK0-005 exam, this concept tests your understanding of Dockerfile optimization and layer caching, often appearing as a scenario where a candidate must identify why a build produces unexpectedly large images or uses old packages. A common trap is thinking separate commands improve readability, but the exam emphasizes efficiency and security. Remember the memory tip: “Update and install, one line to fill—cache won’t kill.”

XK0-005 Scripting, Containers and Automation Practice Question

This XK0-005 practice question tests your understanding of scripting, containers and automation. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

Exhibit

Refer to the exhibit.

FROM ubuntu:20.04
RUN apt-get update
RUN apt-get install -y python3
COPY app.py /app/
CMD ["python3", "/app/app.py"]

Given the Dockerfile in the exhibit, which best practice is being violated?

Clue words in this question

Noticing these words before you look at the options changes how you read each choice.

  • Clue: "best"

    Why it matters: Signals that multiple options may be partially correct. Choose the option that most directly solves the exact problem described, not the one that sounds most complete.

Question 1hardmultiple choice
Full question →

Exhibit

Refer to the exhibit.

FROM ubuntu:20.04
RUN apt-get update
RUN apt-get install -y python3
COPY app.py /app/
CMD ["python3", "/app/app.py"]

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

Not combining apt-get update and install in one RUN command

The Dockerfile violates the best practice of combining `apt-get update` and `apt-get install` in a single RUN command. When these are separated, Docker caches the layer from `apt-get update`, so subsequent builds may use a stale package index, potentially installing outdated or vulnerable packages. Combining them ensures that the update and install happen atomically, reducing image size and guaranteeing a fresh package index.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Not combining apt-get update and install in one RUN command

    Why this is correct

    Should be combined: RUN apt-get update && apt-get install -y python3

    Clue confirmation

    The clue word "best" in the question point toward this answer.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Using a non-LTS base image

    Why it's wrong here

    20.04 is LTS.

  • Not using a .dockerignore file

    Why it's wrong here

    Missing .dockerignore is not a best practice violation for this simple case.

  • Running apt-get update without cache cleanup

    Why it's wrong here

    rm -rf /var/lib/apt/lists/* is recommended, but not the primary violation.

Common exam traps

Common exam trap: answer the scenario, not the keyword

CompTIA often tests the nuance that separating `apt-get update` and `apt-get install` is a caching and security violation, not just a style issue, and candidates may mistakenly focus on cache cleanup or .dockerignore as the primary problem.

Detailed technical explanation

How to think about this question

Docker layers are cached based on the exact command string; separating `apt-get update` and `apt-get install` into two RUN commands means the update layer is cached and reused even if the package index changes, leading to potential security gaps. Combining them with `&&` ensures a single layer, and adding `--no-install-recommends` and cleanup of `/var/lib/apt/lists/*` further minimizes image size. In CI/CD pipelines, this prevents stale builds and reduces attack surface.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A practitioner preparing for the XK0-005 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related XK0-005 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free XK0-005 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this XK0-005 question test?

Scripting, Containers and Automation — This question tests Scripting, Containers and Automation — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: Not combining apt-get update and install in one RUN command — The Dockerfile violates the best practice of combining `apt-get update` and `apt-get install` in a single RUN command. When these are separated, Docker caches the layer from `apt-get update`, so subsequent builds may use a stale package index, potentially installing outdated or vulnerable packages. Combining them ensures that the update and install happen atomically, reducing image size and guaranteeing a fresh package index.

What should I do if I get this XK0-005 question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Are there clue words in this question I should notice?

Yes — watch for: "best". Signals that multiple options may be partially correct. Choose the option that most directly solves the exact problem described, not the one that sounds most complete.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This XK0-005 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-005 exam.