mediumMultiple ChoiceObjective-mapped
XK0-006 docker run Practice Question
An administrator needs to deploy a containerized web application on a Linux server. The application requires port 8080 to be mapped to host port 80. Which command will run the container in detached mode with this port mapping?
⚠ Common exam trap
Watch out — candidates often confuse the order of port mapping in the `-p` flag, mistakenly thinking `-p container_port:host_port` is correct, when the correct syntax is `-p host_port:container_port`. Additionally, option C may be misinterpreted as correct because it maps port 80 on both host and container, but the requirement is to map the container's port 8080 to host port 80.
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 -p 80:8080 webapp
The `-d` flag runs the container in detached mode, and `-p 80:8080` maps host port 80 to container port 8080, matching the requirement. Option D achieves this. Option A is missing the `-d` flag, so it would run in the foreground. Option B uses `-p 8080:80`, which maps host port 8080 to container port 80—the reverse of what is needed. Option C uses `-p 80:80`, which does not expose the container's port 8080. The correct syntax is `-p host_port:container_port`.
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 -p 80:8080 webapp
Why it's wrong here
Missing the -d flag for detached mode; runs container in foreground.
- ✗
docker run -d -p 8080:80 webapp
Why it's wrong here
Incorrect port mapping order; maps host port 8080 to container port 80, opposite of requirement. Also identical to option C.
- ✗
docker run -d -p 80:80 webapp
Why it's wrong here
Incorrect port mapping order; maps host port 8080 to container port 80, opposite of requirement. Also identical to option B.
- ✓
docker run -d -p 80:8080 webapp
Why this is correct
Correct: -d runs detached, -p 80:8080 maps host port 80 to container port 8080 as required.
Go deeper
Related to this question
About these practice questions
Courseiva writes every XK0-006 question from scratch — 979 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.