Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

A container is running a web server on port 8080 internally, and the administrator wants to access it on the host on port 80. Which Docker run option accomplishes this?

⚠ Common exam trap

The trap here is reversing the -p syntax — candidates frequently write -p 8080:80 thinking the container port comes first, but Docker always expects HOST_PORT:CONTAINER_PORT.

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

✓

-p 80:8080

The Docker -p flag maps a host port to a container port using the syntax -p HOST_PORT:CONTAINER_PORT. Since the container listens on 8080 internally and the administrator wants it reachable on host port 80, the correct mapping is -p 80:8080. This publishes the container's port 8080 to the host's port 80.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    -p 80:8080

    Why this is correct

    Publishing with `-p 80:8080` maps host port 80 to container port 8080, satisfying the requirement to reach the internal web server on the host's privileged HTTP port. Docker's port syntax is host:container, so the left value is the externally exposed port and the right is the container's listening port.

  • ✗

    -P

    Why it's wrong here

    The -P flag publishes all exposed container ports to randomly assigned host ports, so the web server would not appear on host port 80. It is tempting because it does publish ports automatically, but the mapping is unpredictable. The -p 80:8080 flag binds host port 80 to container port 8080, which is the explicit mapping this scenario requires.

  • ✗

    -p 8080:80

    Why it's wrong here

    -p 8080:80 maps host port 8080 to container port 80, the reverse of what is required; the host must bind 80 to container 8080. It suits publishing a container's port 80 on a non-privileged host port.

  • ✗

    --expose 8080

    Why it's wrong here

    `--expose 8080` only documents the container port for inter-container links and does not publish it to the host, so nothing listens on host port 80. It is tempting because `--expose` is genuinely used to declare ports for container-to-container communication on a user-defined network, where host publishing is unnecessary.

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 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.