Courseiva
hardMultiple SelectObjective-mapped

XK0-006 Practice Question: Which THREE of the following are valid ways to…

Which THREE of the following are valid ways to define environment variables in a Docker container? (Choose three.)

⚠ Common exam trap

CompTIA often tests the distinction between build-time (`ARG`) and runtime (`ENV`, `-e`, `docker-compose.yml`) variable definitions. Note that `--env-file` is not a definition method but a file-loading method, so it is not included among the three correct ways.

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

Passing with docker run -e VAR=value

Options A, B, and D are valid ways to define environment variables in a Docker container. Option A (`docker run -e VAR=value`) sets a variable at runtime. Option B (specifying environment variables under `services:` in `docker-compose.yml`) defines them for Compose-based deployments. Option D (the `ENV` instruction in a Dockerfile) sets variables that persist in the image and at runtime. Option C (`ARG` in a Dockerfile) is incorrect because ARG defines build-time variables that do not persist in the running container. Option E (`docker run --env-file`) is not a direct definition method; it loads variables from a file, which is a different mechanism.

Answer analysis

Option-by-option breakdown

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

  • Passing with docker run -e VAR=value

    Why this is correct

    Overrides or sets variable at runtime.

  • Including in a docker-compose.yml under services: environment:

    Why this is correct

    Valid for Docker Compose deployments.

  • Using the ARG instruction in Dockerfile

    Why it's wrong here

    ARG is for build arguments, not runtime env.

  • Using the ENV instruction in Dockerfile

    Why this is correct

    Sets environment variable in image.

  • Using --env-file option with docker run

    Why it's wrong here

    This is incorrect because `--env-file` loads environment variables from a file rather than defining them directly; it is not considered a definition method in this context.

About these practice questions

One of 979 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.