Courseiva
Automation, Orchestration, and ScriptingmediumMultiple ChoiceObjective-mapped

XK0-006 CMD instruction Practice Question

A DevOps engineer is writing a Dockerfile for a Python web application. The base image is python:3.9-slim. The application code is in the current directory, and the container should expose port 8080. Which Dockerfile instructions correctly build the image and run the application using python app.py?

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

FROM python:3.9-slim COPY . /app WORKDIR /app EXPOSE 8080 CMD ['python', 'app.py']

It uses the exec form of CMD (CMD ['python', 'app.py']), which directly executes the command without a shell, providing proper signal handling and is the recommended format. Option A uses shell form (CMD python app.py), which runs the command as a subprocess of /bin/sh and may not handle signals correctly, making it less ideal. Additionally, the Dockerfile must include WORKDIR to set the working directory and COPY to add code; all options have these but only B uses the correct CMD syntax.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • FROM python:3.9-slim COPY . /app WORKDIR /app EXPOSE 8080 CMD python app.py

    Why it's wrong here

    This option uses shell form for CMD (CMD python app.py), which runs the command as a subprocess of the shell, potentially causing issues with signal forwarding and process management. The exec form (CMD ['python', 'app.py']) is preferred. Therefore, this option is not correct.

  • FROM python:3.9-slim COPY . /app WORKDIR /app EXPOSE 8080 CMD ['python', 'app.py']

    Why this is correct

    Correct order of instructions; CMD uses JSON array form correctly.

  • FROM python:3.9-slim COPY . /app EXPOSE 8080 ENTRYPOINT python app.py

    Why it's wrong here

    The `ENTRYPOINT` instruction uses shell form (`python app.py`), which does not pass signals from `docker stop` to the Python process, preventing graceful shutdown. The stem requires a runnable application; the correct instruction would be `CMD ["python", "app.py"]` (exec form) to handle signals properly. This option is tempting because `ENTRYPOINT` is often used to define the main container command, and in scenarios where the container should always run the same executable without overrides, `ENTRYPOINT` in shell form is a common (though flawed) choice.

  • FROM python:3.9-slim WORKDIR /app COPY . . EXPOSE 8080 RUN python app.py

    Why it's wrong here

    RUN executes at build time, not runtime. CMD or ENTRYPOINT is needed for runtime.

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.