easyMultiple ChoiceObjective-mapped
XK0-006 Practice Question: A DevOps engineer needs to run a container that…
A DevOps engineer needs to run a container that executes a batch job and then exits. The container image is stored in a private registry. Which Docker command should be used to run the container and automatically remove it after it exits?
⚠ Common exam trap
CompTIA often tests the distinction between `docker run` (creates and starts a new container) and `docker start` (restarts an existing container), and the trap here is that candidates may confuse `--rm` as a generic cleanup flag applicable to any Docker command, when it is only valid with `docker run`.
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
✓
docker run --rm private.registry.com/batch:latest
The `docker run --rm` command automatically removes the container after it exits, which is ideal for batch jobs that should not leave behind stopped containers. The image reference `private.registry.com/batch:latest` pulls from a private registry when not cached locally. This combination ensures the container runs once, completes its task, and is cleaned up without manual intervention.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
docker run --rm private.registry.com/batch:latest
Why this is correct
The --rm flag ensures the container is removed after it exits, and the image is pulled from the registry.
- ✗
docker start --rm private.registry.com/batch:latest
Why it's wrong here
docker start is used to start an existing container, not to run a new one from an image.
- ✗
docker run -d private.registry.com/batch:latest
Why it's wrong here
Without --rm, the container is not automatically removed after exit.
- ✗
docker exec --rm private.registry.com/batch:latest
Why it's wrong here
docker exec runs a command in an existing container, not a new one.
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.