CKAD Application Design and Build Practice Question
Which of the following Dockerfile instructions sets the working directory for any subsequent RUN, CMD, ENTRYPOINT, COPY, and ADD instructions?
⚠ Common exam trap
This question tests understanding that WORKDIR sets the working directory for subsequent instructions, distinguishing it from USER (which sets the runtime user) and COPY (which copies files).
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
✓
WORKDIR
The WORKDIR instruction sets the working directory for any subsequent RUN, CMD, ENTRYPOINT, COPY, and ADD instructions in the Dockerfile. If the directory does not exist, it will be created automatically, and it persists across all subsequent instructions until changed by another WORKDIR.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
EXPOSE
Why it's wrong here
EXPOSE is a metadata instruction that documents which ports the container listens on, but it has no effect on the filesystem or the process's current working directory. It is used for image documentation and to inform Docker desktop or orchestration tools about expected network ports. Therefore, it cannot set the working directory for subsequent build instructions or the runtime process.
- ✓
WORKDIR
Why this is correct
WORKDIR sets the working directory for all subsequent Dockerfile instructions, including RUN, CMD, ENTRYPOINT, COPY, and ADD. It automatically creates the directory if it does not exist, and it can be used multiple times to change the directory for later steps. At runtime, this becomes the initial working directory of the container process, so any relative paths or shell commands execute from that location.
- ✗
COPY
Why it's wrong here
COPY is a build instruction that copies files or directories from the build context (host) into the image filesystem at a specified destination path. While the destination path may place files into a particular directory, COPY does not alter the default working directory that subsequent instructions or the container process will use. The working directory remains whatever was set by the last WORKDIR, or the root if none was set.
- ✗
USER
Why it's wrong here
USER sets the username or UID that will be used to run any subsequent RUN instructions as well as the default user for the container process at runtime. This instruction affects security and permission context, but it is completely unrelated to filesystem paths and does not change the current directory. Thus, USER cannot be used to set the working directory.
About these practice questions
This CKAD question is part of Courseiva's 826-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 →
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.