Courseiva
mediumMultiple Select

XK0-006 Practice Question: Which TWO options are valid ways to pass…

Which TWO options are valid ways to pass environment variables to a Docker container?

⚠ Common exam trap

Many candidates confuse the `-v` flag (used for volumes) with environment variable flags, or assume `--var` or `--variable` are valid Docker options when they are not.

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

✓

--env-file file

The `--env-file` flag allows you to pass a file containing environment variables to a Docker container, where each line in the file is in `KEY=value` format. Option C is correct because the `-e` (or `--env`) flag directly sets an environment variable inside the container, e.g., `-e VAR=value`. Both are standard Docker CLI methods for injecting environment variables at container runtime.

Answer analysis

Option-by-option breakdown

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

  • ✗

    --var VAR=value

    Why it's wrong here

    Docker defines no --var flag; the documented options are -e, --env and --env-file. The abbreviation looks like a natural shorthand for variable, which explains its appeal, yet the CLI parses only the exact registered flag names and would error on --var.

  • ✓

    --env-file file

    Why this is correct

    The --env-file flag reads a file containing VAR=value lines and injects each as an environment variable in the container. It satisfies the stem's requirement for a valid way to pass environment variables, allowing bulk configuration without repeating -e flags.

  • ✓

    -e VAR=value

    Why this is correct

    The -e flag sets a single environment variable directly in the container at runtime, for example -e VAR=value. It satisfies the stem's requirement for a valid way to pass environment variables, injecting the value into the container's environment without a file.

  • ✗

    --variable VAR=value

    Why it's wrong here

    Docker has no --variable flag; environment variables are supplied with -e or --env, or via --env-file. The name resembles the real --env option, which is what makes it plausible, but Docker's CLI rejects --variable outright rather than mapping it to environment injection.

  • ✗

    -v VAR=value

    Why it's wrong here

    The -v flag mounts a host path or named volume into the container filesystem; it has no environment-variable syntax, so VAR=value is parsed as a volume specification. It is tempting because -v is a genuine, frequently used docker run flag, but for environment variables the correct flags are -e or --env.

About these practice questions

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