Courseiva
easyMultiple Choice

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

    The -d flag detaches the container, --name web assigns the required name, and -p 8080:80 maps host port 8080 to container port 80. Specifying nginx as the image completes the command, satisfying every constraint in the stem exactly.

  • ✗

    docker exec -d --name web -p 8080:80 nginx

    Why it's wrong here

    docker exec runs a command inside an already-running container and cannot create one, so --name and -p are invalid here. It is tempting because exec is the right tool when you need to launch an additional process, such as a shell or script, inside a container that is already up.

  • ✗

    docker start -d --name web -p 8080:80 nginx

    Why it's wrong here

    docker start restarts an existing stopped container and accepts neither --name nor -p, since port mappings and names are fixed at creation. It is tempting because start is correct when you need to bring a previously created container back up without recreating it.

  • ✗

    docker run -it --name web -p 8080:80 nginx

    Why it's wrong here

    Runs in interactive mode, not detached.

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