Courseiva
hardMultiple ChoiceObjective-mapped

XK0-006 Practice Question: A system administrator is troubleshooting a…

A system administrator is troubleshooting a Docker container that exits immediately after starting. The container is built from a minimal image that runs a short-lived command. Which change will keep the container running?

⚠ Common exam trap

CompTIA often tests the misconception that detached mode (`-d`) or restart policies (`--restart=always`) can keep a container running indefinitely, but the core requirement is that the container's main process must not terminate.

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

Modify the Dockerfile to use CMD ["sh"] instead of CMD ["echo", "hello"]

The container exits immediately when its main process finishes. By changing the CMD from `["echo", "hello"]` (which prints a message and exits) to `["sh"]`, the container runs an interactive shell that waits for input, keeping the process alive and the container running. In Docker, a container lives only as long as its PID 1 process runs.

Answer analysis

Option-by-option breakdown

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

  • Modify the Dockerfile to use CMD ["sh"] instead of CMD ["echo", "hello"]

    Why this is correct

    Running a shell as the main process will keep the container running indefinitely.

  • Use -d flag to run in detached mode

    Why it's wrong here

    Detached mode does not prevent the process from exiting; it just runs in the background.

  • Restart the container with --restart=always

    Why it's wrong here

    This will keep restarting the container but it will still exit immediately each time, causing a continuous restart loop.

  • Allocate a pseudo-TTY with -t flag

    Why it's wrong here

    Allocating a TTY alone does not keep the container running; the process must still be long-lived.

About these practice questions

This XK0-006 question is part of Courseiva's 979-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.