Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

A Linux administrator needs to run a Docker container in detached mode with port mapping from host port 8080 to container port 80, and mount a host directory /data to /app/data inside the container. Which command achieves this?

⚠ Common exam trap

Many exam-takers confuse `-p` (specific port mapping) with `-P` (publish all exposed ports to random host ports), and mixing up `docker run` with `docker start`; candidates may also overlook that `-it` is not detached mode.

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 8080:80 -v /data:/app/data --name webapp nginx

It uses `docker run -d` to start the container in detached mode (background), `-p 8080:80` to map host port 8080 to container port 80, and `-v /data:/app/data` to bind-mount the host directory `/data` to the container path `/app/data`. The `--name webapp` assigns a friendly name, and `nginx` specifies the image. This combination exactly matches all requirements.

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 -p 8080:80 -v /data:/app/data --name webapp nginx

    Why this is correct

    The -d flag detaches the container, -p 8080:80 maps host port 8080 to container port 80, and -v /data:/app/data bind-mounts the host directory. Together these satisfy every stated constraint in a single command, using the nginx image.

  • ✗

    docker run -it -p 8080:80 -v /data:/app/data --name webapp nginx

    Why it's wrong here

    The -it flags allocate an interactive TTY and attach to the foreground, contradicting the detached-mode requirement that -d satisfies. It is tempting because -p 8080:80 and the -v /data:/app/data bind mount are exactly right, so only the mode flag is wrong.

  • ✗

    docker run -d -P -v /data:/app/data --name webapp nginx

    Why it's wrong here

    -P publishes every exposed container port to random ephemeral host ports, so host port 8080 is not mapped to container port 80. It is tempting because -d and the /data:/app/data bind mount are correct; -P suits throwaway containers where the host port is irrelevant.

  • ✗

    docker start -d -p 8080:80 -v /data:/app/data webapp

    Why it's wrong here

    docker start only restarts an existing stopped container; it accepts no -p or -v flags, so the port mapping and bind mount are never applied. It is tempting because it targets the named webapp container, and would be right for restarting a container already created with those settings.

About these practice questions

One of 781 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 →

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.