CKAD Application Design and Build Practice Question
What is the purpose of the '.dockerignore' file?
⚠ Common exam trap
The CKAD exam often tests the distinction between build-time context exclusion (`.dockerignore`) and runtime image content (Dockerfile instructions), so candidates may mistakenly think `.dockerignore` controls what goes into the final image rather than what is sent to the Docker daemon.
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
✓
To exclude files from the build context
The `.dockerignore` file is used to exclude files and directories from the build context sent to the Docker daemon during a `docker build` operation. By specifying patterns in this file, you prevent unnecessary or sensitive files (like local development artifacts, `.git` directories, or node_modules) from being included, which speeds up the build and reduces the image size. Option C correctly identifies this purpose.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
To specify which files to include in the image
Why it's wrong here
The .dockerignore file functions exclusively to exclude paths; it does not act as a whitelist or inclusion manifest. If you want specific files to appear in an image, you must copy them into the build context and reference them with COPY/ADD instructions in the Dockerfile. Attempting to use .dockerignore to select files would be inverted logic—any file not excluded remains in the context, but no file is ever explicitly pulled in by this file.
- ✗
To ignore files during docker push
Why it's wrong here
This option misattributes the effect to image push operations. The .dockerignore file is evaluated by the Docker client before the build starts, filtering the build context sent to the daemon; it has zero influence on `docker push`, which uploads already-existing image layers to a registry. Files omitted from the context never become part of any layer, so pushing an image cannot be altered by .dockerignore.
- ✓
To exclude files from the build context
Why this is correct
The correct purpose is to exclude files and directories from the build context that the Docker client sends to the Docker daemon, shrinking the upload size and preventing sensitive or irrelevant data from reaching layer builds. Any path listed in .dockerignore is absent from the context, meaning COPY/ADD cannot access those files at all, and changes to them won't invalidate the build cache. This is the intended, documented behavior of the file.
- ✗
To list environment variables to ignore
Why it's wrong here
Environment variables are managed within the Dockerfile using the ENV instruction or passed at build time via --build-arg, so .dockerignore has no mechanism to define or ignore them. The file's pattern-matching logic operates purely on filesystem paths relative to the build context, not on process metadata or container configuration. Listing a variable name like FOO=bar in .dockerignore would simply be interpreted as a path pattern and silently ignored.
Go deeper
Related to this question
About these practice questions
Courseiva writes every CKAD question from scratch — 826 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 CKAD practice question is part of Courseiva's free CNCF 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 CKAD exam.