Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

A DevOps engineer needs to run a Docker container in the background with port mapping from host port 8080 to container port 80, and name the container 'webapp'. Which command accomplishes this?

⚠ Common exam trap

XK0-006 often tests the confusion between `docker run`, `docker create`, and `docker start` — candidates pick `create` or `start` thinking they launch a container, but only `run` both creates and starts it with the required 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 -p 8080:80 --name webapp nginx

`docker run` is the command that creates AND starts a container in one step, and the `-d` flag detaches it to run in the background. The `-p 8080:80` flag maps host port 8080 to container port 80, and `--name webapp` assigns the container name. This is the canonical single-command way to launch a named, port-mapped, background container from the nginx image.

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 start -d -p 8080:80 --name webapp nginx

    Why it's wrong here

    docker start only restarts an existing stopped container and accepts no -p, --name, or image arguments, so it cannot create 'webapp' or publish 8080:80. It is tempting because -d exists, but it is correct only when the container was previously created and merely needs restarting.

  • ✗

    docker create -d -p 8080:80 --name webapp nginx

    Why it's wrong here

    docker create only constructs the container; it never starts it, so nothing runs in the background despite -d. The task requires docker run -d, which creates and starts in one step. docker create is correct when you intend to configure a container first and start it later with docker start.

  • ✓

    docker run -d -p 8080:80 --name webapp nginx

    Why this is correct

    The -d flag detaches the container to run in the background, -p 8080:80 maps host port 8080 to container port 80, and --name webapp assigns the required container name. The nginx image supplies the container workload, satisfying every constraint in the stem.

  • ✗

    docker compose up -d -p 8080:80 --name webapp nginx

    Why it's wrong here

    docker compose up reads a compose file and rejects -p, --name, and a bare image argument; port and container name belong in the YAML service definition. It is tempting as the orchestration tool, but it is correct only when a compose file already declares the service, ports, and container_name.

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.