Courseiva
Application Design and BuildeasyMultiple ChoiceObjective-mapped

CKAD Application Design and Build Practice Question

What is the purpose of a .dockerignore file in a Docker build context?

⚠ Common exam trap

The CKAD exam often tests the distinction between build-time and runtime configuration; the trap here is confusing the .dockerignore file (which affects the build context sent to the daemon) with files that control image layers or container runtime behavior, leading candidates to select options about layer count or environment variables.

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 excludes files and directories from being sent to the Docker daemon during the build

The .dockerignore file, when placed in the Docker build context, instructs the Docker CLI to exclude specified files and directories from the tar archive that is sent to the Docker daemon during the `docker build` command. This reduces the build context size, speeds up the build, and prevents sensitive files (e.g., .env, .git) from being included in the image layers.

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 limits the number of layers in the final image

    Why it's wrong here

    The number of layers in a Docker image is determined solely by the instructions written in the Dockerfile—each RUN, COPY, and ADD step creates a new layer. A .dockerignore file only filters which files are sent as the build context to the Docker daemon; it does not alter the execution of those instructions or the resulting layer count.

  • It excludes files and directories from being sent to the Docker daemon during the build

    Why this is correct

    A .dockerignore file defines patterns that exclude files and directories from the build context before it is transmitted to the Docker daemon. This reduces the amount of data sent, shortens build times, and prevents sensitive information like .env, SSH keys, or large local caches such as node_modules from being uploaded. Ignored files are not available for COPY or ADD within the Dockerfile, but the exclusion is purely at the context-transmission stage.

  • It defines environment variables for the container

    Why it's wrong here

    The .dockerignore file is not parsed as a Dockerfile and has no mechanism for setting environment variables. Container environment variables are defined explicitly via the ENV instruction in the Dockerfile, via ARG+ENV build-time variables, or at runtime with docker run -e or a Compose environment block. The .dockerignore operates before any build instruction, exclusively controlling the contents of the build context.

  • It specifies the order of layers in the Docker image

    Why it's wrong here

    Layer ordering is a direct consequence of the sequence of instructions in the Dockerfile; each instruction appends a new layer to the image filesystem. The .dockerignore file merely removes matching files from the build context tar, which may be referenced by COPY or ADD, but it cannot change the order or existence of layers. Reordering layers requires restructuring your Dockerfile, not editing .dockerignore.

About these practice questions

This CKAD question is part of Courseiva's 160-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.