XK0-006 Automation, Orchestration, and Scripting Practice Question
A user wants to run a Docker container in detached mode, remove it automatically after it stops, and map host port 8080 to container port 80. Which command accomplishes this?
⚠ Common exam trap
Many exam-takers confuse `docker create` with `docker run` and assuming `docker start` can apply port mappings — candidates often forget that port bindings and `--rm` are fixed at container creation time and cannot be added later.
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 -d --rm -p 8080:80 image
The `docker run` command is the correct choice because it combines container creation and startup in a single step. The `-d` flag runs the container in detached mode (in the background), `--rm` automatically removes the container filesystem when it exits, and `-p 8080:80` maps host port 8080 to container port 80. Together these flags satisfy all three requirements in one command.
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 -d --rm -p 8080:80 image
Why this is correct
The -d flag detaches the container, --rm deletes it automatically once stopped, and -p 8080:80 publishes host port 8080 to container port 80. All three stem constraints are satisfied in a single command, with the image name supplied last as the positional argument.
- ✗
docker run -it --rm -p 80:8080 image
Why it's wrong here
The port mapping is reversed: -p 80:8080 publishes container port 8080 on host port 80, not host 8080 to container 80. It also attaches an interactive TTY, contradicting detached mode. The -p host:container form with -d is what the scenario requires.
- ✗
docker create --rm -p 8080:80 image
Why it's wrong here
docker create only instantiates a stopped container; it never starts it, so detached execution and automatic removal on stop cannot occur. It is tempting because --rm and -p are accepted flags, but create would be correct when preparing a container to be started later with docker start.
- ✗
docker start -d -p 8080:80 image
Why it's wrong here
docker start only restarts an existing stopped container and accepts neither -p nor -d for creating new port bindings, so the mapping is ignored. It is tempting because -d suggests detachment, but start would be correct when resuming a container previously created with the desired configuration.
Go deeper
Related to this question
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 →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official CompTIA exam blueprint
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.