easyMultiple ChoiceObjective-mapped
XK0-006 Practice Question: Which command will run a container in detached…
Which command will run a container in detached mode with the name 'web' and map host port 8080 to container port 80, using the nginx image?
⚠ Common exam trap
CompTIA often tests the distinction between `docker run` (create + start) and `docker start` (start existing container), and the requirement for `-d` versus `-it` to achieve detached mode, causing candidates to confuse the subcommands or flags.
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 --name web -p 8080:80 nginx
`docker run` creates and starts a new container. The `-d` flag runs it in detached mode (background), `--name web` assigns the name 'web', `-p 8080:80` maps host port 8080 to container port 80, and `nginx` specifies the image to use. This is the standard syntax for deploying a container with port mapping and a custom name.
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 --name web -p 8080:80 nginx
Why this is correct
Correct. This runs the nginx container in detached mode with the specified name and port mapping.
- ✗
docker exec -d --name web -p 8080:80 nginx
Why it's wrong here
Exec runs a command in an existing container, not suitable for starting a new container with port mapping.
- ✗
docker start -d --name web -p 8080:80 nginx
Why it's wrong here
The start command does not accept port mapping or image specification.
- ✗
docker run -it --name web -p 8080:80 nginx
Why it's wrong here
Runs in interactive mode, not detached.
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.