0
0
Dockerdevops~20 mins

Copying from build stage to final stage in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multi-stage Docker 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 copying files
Given the following Dockerfile, what will be the output when running docker build .?
Docker
FROM alpine AS builder
RUN echo 'Hello from builder' > /message.txt

FROM alpine
COPY --from=builder /message.txt /final_message.txt
CMD cat /final_message.txt
AHello from builder
Bcat: /final_message.txt: No such file or directory
CError: COPY failed
DHello from final stage
Attempts:
2 left
💡 Hint
The COPY --from=builder copies files from the build stage named 'builder'.
Configuration
intermediate
1:30remaining
Correct COPY syntax for multi-stage build
Which COPY command correctly copies the directory /app from the build stage named builder to the final stage's /app directory?
ACOPY /app builder:/app
BCOPY /app /app --from=builder
CCOPY builder:/app /app
DCOPY --from=builder /app /app
Attempts:
2 left
💡 Hint
The --from flag must come immediately after COPY.
Troubleshoot
advanced
2:30remaining
Why does COPY --from fail in this Dockerfile?
You have this Dockerfile snippet: FROM node:18 AS builder WORKDIR /app RUN echo 'build files' > build.txt FROM node:18 COPY --from=build /app/build.txt /app/build.txt Why does the build fail with error: 'COPY failed: stat /var/lib/docker/tmp/...: no such file or directory'?
AThe final stage must be named 'builder' to copy files
BThe source path /app/build.txt does not exist in the builder stage
CThe build stage is named 'builder', but COPY uses 'build' which does not exist
DCOPY cannot copy files from previous stages
Attempts:
2 left
💡 Hint
Check the stage name after AS and the name used in --from.
🔀 Workflow
advanced
2:00remaining
Order of stages in multi-stage Dockerfile
In a multi-stage Dockerfile, which statement is true about copying files from a build stage to the final stage?
AThe build stage must appear before the final stage in the Dockerfile
BYou cannot copy files between stages
CStages can be in any order; Docker resolves them automatically
DThe final stage must appear before the build stage
Attempts:
2 left
💡 Hint
Think about how Docker builds stages sequentially.
Best Practice
expert
3:00remaining
Optimizing multi-stage Docker builds for smaller final images
Which approach best reduces the final image size when copying artifacts from a build stage?
ACopy the entire build directory to the final stage
BCopy only the necessary files from the build stage using specific paths
CInstall build tools in the final stage and build there
DUse a single-stage build with all tools installed
Attempts:
2 left
💡 Hint
Think about minimizing what goes into the final image.