0
0
Dockerdevops~20 mins

Named build stages in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Named Build Stages Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of multi-stage Docker build with named stages
Given the Dockerfile below, what will be the output of the final image when running docker run --rm myapp?
Docker
FROM alpine AS builder
RUN echo "Hello from builder" > /message.txt

FROM alpine
COPY --from=builder /message.txt /message.txt
CMD ["cat", "/message.txt"]
A
Hello from builder
B
cat: /message.txt: No such file or directory
C
Hello from alpine
DError: COPY failed
Attempts:
2 left
💡 Hint
Look at how the --from=builder copies the file from the named stage.
Configuration
intermediate
1:30remaining
Correct syntax for naming a build stage
Which of the following Dockerfile snippets correctly names a build stage as 'test'?
A
FROM node AS test
RUN npm test
B
FROM node WITH test
RUN npm test
C
FROM node NAMED test
RUN npm test
D
FROM node STAGE test
RUN npm test
Attempts:
2 left
💡 Hint
The keyword to name a stage is 'AS'.
Troubleshoot
advanced
1:30remaining
Troubleshooting COPY from a non-existent stage
What error will Docker produce if you try to copy from a named stage that does not exist?
Docker
FROM alpine
COPY --from=builder /file.txt /file.txt
ACOPY succeeded but file is empty
BError: unknown stage name builder
CNo error, file copied from base image
DError: file /file.txt not found
Attempts:
2 left
💡 Hint
Check if the stage name used in COPY matches any defined stage.
🔀 Workflow
advanced
1:30remaining
Order of stages in a multi-stage Dockerfile
In a Dockerfile with multiple named stages, which stage is used as the final image by default?
AThe first stage defined in the Dockerfile
BThe stage specified by the --target option only
CThe stage named 'final' if it exists
DThe last stage defined in the Dockerfile
Attempts:
2 left
💡 Hint
If no target is specified, Docker uses a default stage.
Best Practice
expert
2:30remaining
Best practice for reducing image size using named build stages
Which approach best reduces the final Docker image size when using named build stages?
AUse a single stage Dockerfile with all dependencies installed
BInstall all build tools in the final stage to avoid copying files
CUse a heavy builder stage with all tools, then copy only necessary artifacts to a minimal final stage
DCopy all files from the builder stage to the final stage to ensure completeness
Attempts:
2 left
💡 Hint
Think about separating build environment from runtime environment.