CKAD Application Design and Build Practice Question
You have a Dockerfile with a multi-stage build. The first stage is named 'builder' and uses 'golang:1.20' to compile a binary. The second stage uses 'alpine:3.18' and should copy the binary from the first stage. Which COPY instruction is correct?
⚠ Common exam trap
The exam often tests the distinction between `COPY` and `ADD` in multi-stage builds, and the trap here is that candidates may incorrectly use `ADD --from` (which is invalid) or forget the `--from` flag entirely, thinking `COPY` defaults to copying from a previous stage.
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
✓
COPY --from=builder /app/myapp /usr/local/bin/myapp
In a multi-stage Docker build, the `COPY --from=<name|index>` instruction copies files from a named previous stage. Option D correctly uses the stage name 'builder' to copy the compiled binary from the first stage into the final Alpine image. This is the standard and most readable approach for multi-stage builds.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
ADD --from=builder /app/myapp /usr/local/bin/myapp
Why it's wrong here
ADD lacks the --from flag entirely; that flag exists only on COPY for multi-stage builds. Running docker build would fail with an invalid flag error before any copy logic is evaluated. Even if the flag existed, ADD is intended for context tarballs/URLs, not for referencing another stage's filesystem.
- ✗
COPY /app/myapp /usr/local/bin/myapp
Why it's wrong here
This form copies from the build context, so it looks for app/myapp relative to the Dockerfile directory — but the compiled binary is produced inside the builder stage, not in the context. Unless you prebuilt the binary on the host, this COPY will fail with "file not found" in the context. Multi-stage builds require the --from=<stage> flag to access intermediate stage artifacts.
- ✗
COPY --from=0 /app/myapp /usr/local/bin/myapp
Why it's wrong here
Using --from=0 numerically references the first stage in the Dockerfile, so it technically works today and copies the same binary. However, it is fragile: inserting or reordering a stage before builder changes the index, silently pointing to a different stage or breaking the build. Named stages (--from=builder) are self-documenting and immune to reordering.
- ✓
COPY --from=builder /app/myapp /usr/local/bin/myapp
Why this is correct
This is the canonical multi-stage build pattern: the final stage copies only the compiled artifact from the named builder stage, leaving build tools and intermediate files out of the runtime image. The flag --from=builder references the stage defined earlier in the Dockerfile, and the destination /usr/local/bin/myapp makes the binary available on PATH. This minimizes image size and attacksurface, which is the main reason multi-stage builds are recommended.
Go deeper
Related to this question
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.