mediumMultiple SelectObjective-mapped
XK0-006 Practice Question: Which two of the following are valid methods to…
Which two of the following are valid methods to pass environment variables to a Docker container at runtime? (Select TWO.)
⚠ Common exam trap
CompTIA often tests the distinction between build-time instructions (`ENV`, `ARG`) and runtime options (`-e`, `--env-file`), so the trap here is confusing the `ENV` instruction in the Dockerfile (which sets variables at build time) with the `-e` option (which sets variables at runtime).
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
✓
Defining variables in a .env file and using --env-file
The `--env-file` flag in `docker run` allows you to pass environment variables from a file (typically a `.env` file) to the container at runtime. This method is useful for managing multiple variables without cluttering the command line and supports variable substitution and quoting rules as defined by Docker.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Defining variables in a .env file and using --env-file
Why this is correct
The --env-file option loads environment variables from a file at runtime.
- ✓
Using the -e option in docker run
Why this is correct
The -e flag sets environment variables when starting a container.
- ✗
Using the ENV instruction in the Dockerfile
Why it's wrong here
ENV sets variables during image build, not at runtime. They become baked into the image.
- ✗
Using the export command inside the container
Why it's wrong here
export sets variables in the container's shell session, but not as container environment variables.
- ✗
Using the ARG instruction in the Dockerfile
Why it's wrong here
ARG defines build-time variables that are not persisted in the final image unless used with ENV.
Go deeper
Related to this question
About these practice questions
Courseiva writes every XK0-006 question from scratch — 979 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
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.