Courseiva
Automation, Orchestration, and ScriptinghardMultiple SelectObjective-mapped

XK0-006 Automation, Orchestration, and Scripting Practice Question

A DevOps engineer is writing a Bash script to automate deployment of a containerized application. The script must: (1) exit immediately if any command fails, (2) build a Docker image with tag 'myapp:latest' from the current directory, (3) run a container from that image in detached mode with port mapping 8080:80, (4) set environment variable ENV=production inside the container, and (5) bind mount a host directory /data to /app/data inside the container. Which TWO of the following snippets should be included in the script to meet these requirements? (Choose TWO.)

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

set -e

(`set -e`) ensures the script exits immediately if any command fails, satisfying requirement 1. Option C (`docker build -t myapp:latest .`) builds the Docker image with the required tag, satisfying requirement 2. The run commands (A and E) are not selected because requirement 2 (building the image) must be completed before running the container, and the question asks for two snippets that meet the requirements; the run command would be a separate part of the script. Option D is also a valid build command but uses the long form `--tag`; either C or D would work, but C is the more common short form. Option E has a syntax error (`-eENV=production` missing space).

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 -e ENV=production -v /data:/app/data myapp:latest

    Why it's wrong here

    This `docker run` command correctly meets requirements 3, 4, and 5, but it does not handle requirement 2 (building the image) or requirement 1 (exit on error).

  • set -e

    Why this is correct

    Correct. `set -e` causes the script to exit if any command fails, satisfying requirement 1.

  • docker build -t myapp:latest .

    Why this is correct

    Correct. `docker build -t myapp:latest .` builds the image from the current directory with the specified tag, satisfying requirement 2.

  • docker build --tag myapp:latest .

    Why it's wrong here

    This command also builds the image correctly using the long form `--tag`, but it is functionally identical to C; only one build command is needed.

  • docker run -d -p 8080:80 -eENV=production -v /data:/app/data myapp:latest

    Why it's wrong here

    This `docker run` command has a syntax error (`-eENV=production` should be `-e ENV=production`), so it is invalid.

About these practice questions

This XK0-006 question is part of Courseiva's 979-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 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.