Courseiva
hardMultiple Choice

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

    Replacing the one-shot `echo` with an interactive shell gives the container a long-running foreground process (PID 1), so Docker does not treat it as exited. The stem's constraint — a minimal image whose command terminates immediately — is satisfied because `sh` blocks awaiting input, keeping the container alive.

  • ✗

    Use -d flag to run in detached mode

    Why it's wrong here

    Detached mode only backgrounds the container, returning the terminal while the short-lived command still completes and the container exits. -d is for running long-lived services without blocking the shell, not for extending a process that finishes immediately.

  • ✗

    Restart the container with --restart=always

    Why it's wrong here

    Restart policies only re-run the container after its main process exits, so a short-lived command still terminates and loops rather than staying up. --restart=always suits long-running services that crash unexpectedly, not images whose entrypoint simply finishes.

  • ✗

    Allocate a pseudo-TTY with -t flag

    Why it's wrong here

    A pseudo-TTY keeps the container attached to an interactive terminal, but the short-lived command still exits, so the container stops. It is tempting because -t is commonly paired with -it for interactive shells, and it would be correct when the container must accept terminal input rather than persist after its command completes.

About these practice questions

This XK0-006 question is part of Courseiva's 781-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.