Challenge - 5 Problems
Multi-stage Docker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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
Attempts:
2 left
💡 Hint
The COPY --from=builder copies files from the build stage named 'builder'.
✗ Incorrect
The file /message.txt is created in the builder stage and copied to the final stage as /final_message.txt. The CMD prints its content.
❓ Configuration
intermediate1: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?Attempts:
2 left
💡 Hint
The --from flag must come immediately after COPY.
✗ Incorrect
The correct syntax is COPY --from=builder source destination. Options B, C, and D are invalid syntax.
❓ Troubleshoot
advanced2: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'?
Attempts:
2 left
💡 Hint
Check the stage name after AS and the name used in --from.
✗ Incorrect
The build stage is named 'builder', but COPY uses --from=build which is undefined, causing the error.
🔀 Workflow
advanced2: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?
Attempts:
2 left
💡 Hint
Think about how Docker builds stages sequentially.
✗ Incorrect
Docker builds stages in order. To copy from a build stage, it must be defined before the final stage.
✅ Best Practice
expert3: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?
Attempts:
2 left
💡 Hint
Think about minimizing what goes into the final image.
✗ Incorrect
Copying only needed files avoids bloating the final image with unnecessary build artifacts or tools.