Courseiva

XK0-006 Automation, Orchestration, and Scripting Practice Question

A container is running and a technician needs to execute an interactive shell inside it. The container was started with 'docker run -d --name myapp myimage'. Which command will achieve this?

⚠ Common exam trap

The trap is confusing 'docker exec' (enter a running container) with 'docker attach' (connect to PID 1's stdio) or 'docker run' (create a new container) — candidates often pick attach or run when the container is already running.

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 exec -it myapp /bin/bash

'docker exec -it myapp /bin/bash' attaches a new interactive TTY session to the already-running container named myapp and launches /bin/bash inside it. The -i flag keeps STDIN open and -t allocates a pseudo-TTY, which is required for an interactive shell. Because the container is already running, exec is the correct tool rather than run.

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 exec -it myapp /bin/bash

    Why this is correct

    docker exec runs a new process inside an already-running container, and the -it flags allocate an interactive TTY plus stdin, giving a shell. Because the container was started detached with -d and named myapp, this satisfies the stem's requirement without restarting or replacing it.

  • ✗

    docker attach myapp

    Why it's wrong here

    docker attach binds to the container's PID 1 stdio, so it only works if that process reads stdin; a detached daemon typically ignores it, and detaching risks stopping the container. It is tempting as the direct route into a running container, and suits attaching to a foreground process you own.

  • ✗

    docker run -it --name myapp myimage /bin/bash

    Why it's wrong here

    docker run creates a new container, and the name myapp is already taken, so it fails with a conflict rather than entering the existing one. It is tempting because -it allocates the interactive TTY a shell needs, and would be correct for starting a fresh container interactively.

  • ✗

    docker logs -f myapp

    Why it's wrong here

    docker logs streams the container's stdout and stderr; it opens no shell and sends no commands into the running process. It is tempting because it inspects a live container by name, and would be the right choice for tailing application output or debugging crashes, not for interactive command execution.

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.