Courseiva

CKAD Application Design and Build Practice Question

Which TWO statements about the .dockerignore file are true?

⚠ Common exam trap

The CKAD exam often tests the misconception that .dockerignore affects all Docker commands, when in reality it only applies to the docker build context, not to docker run, docker push, or other commands.

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

✓

It supports pattern matching similar to .gitignore

The .dockerignore file supports pattern matching using glob patterns, similar to .gitignore. This allows you to define patterns to exclude files and directories from the Docker build context, preventing them from being sent to the Docker daemon during a build.

Answer analysis

Option-by-option breakdown

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

  • ✗

    It is automatically applied to all docker commands

    Why it's wrong here

    The .dockerignore file only affects the build context sent to the Docker daemon during `docker build`; it is not consulted by commands such as `docker run`, `docker push`, `docker pull`, or `docker save`. Its scope is limited to that single build operation, and it has no influence on container runtime behavior or image distribution.

  • ✓

    It supports pattern matching similar to .gitignore

    Why this is correct

    The .dockerignore file follows standard Go filepath.Match glob rules and supports patterns like `*`, `?`, character classes, and `**` for directory trees, closely mirroring .gitignore semantics. This allows users to define broad exclusion rules, such as `*/temp*` or `**/*.md`, to filter the build context efficiently. It also supports comments and negation with `!`, though re-inclusion after an exclusion requires careful path handling.

  • ✗

    It can be used to specify which Dockerfile to use

    Why it's wrong here

    The Dockerfile to be used for a build is selected via the `-f` or `--file` flag on `docker build`, or defaults to a file named `Dockerfile` in the root of the build context. The `.dockerignore` file has no mechanism to point to a different Dockerfile; its sole purpose is to filter files from the build context. Confusing this with file selection conflates two separate concerns in the build process.

  • ✗

    It can override the base image from the Dockerfile

    Why it's wrong here

    The base image for a build is determined exclusively by the `FROM` instruction inside the Dockerfile, which the build process reads from the build context. A `.dockerignore` file only removes files from the context before the build; it cannot alter or replace image references or any other instruction in the Dockerfile. Docker ignores the content of `.dockerignore` when parsing the build steps, so it has zero effect on image resolution.

  • ✓

    It can exclude files from being copied into the image by COPY and ADD instructions

    Why this is correct

    When `.dockerignore` excludes a file or directory, that path is not sent to the Docker daemon as part of the build context, so any `COPY` or `ADD` instruction that references it will fail or be skipped, effectively preventing that content from being baked into the image. This is a primary use case to avoid copying temporary artifacts, secrets, or version control directories. Because the exclusion happens at context assembly time, it also reduces the size of the context upload, making builds faster and more secure.

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 →

How Courseiva writes practice questions · Editorial policy

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.