Challenge - 5 Problems
Multi-stage 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 for static site
Given this Dockerfile for a static site using multi-stage build, what will be the output of
docker images after building?Nginx
FROM node:18 AS builder WORKDIR /app COPY . . RUN npm install && npm run build FROM nginx:alpine COPY --from=builder /app/dist /usr/share/nginx/html
Attempts:
2 left
💡 Hint
Think about what the final stage in a multi-stage build produces as the image.
✗ Incorrect
Multi-stage builds produce only the final stage as the image. The builder stage is temporary and not saved as an image unless tagged separately.
❓ Configuration
intermediate1:30remaining
Correct COPY command in multi-stage Dockerfile
Which COPY command correctly copies the built static files from the builder stage to the nginx image in a multi-stage Dockerfile?
Attempts:
2 left
💡 Hint
Remember to specify the source stage and correct source and destination paths.
✗ Incorrect
The correct syntax is COPY --from=builder . The source is the build output directory in the builder stage.
🔀 Workflow
advanced2:30remaining
Order of steps in multi-stage Dockerfile for static site
Arrange the following steps in the correct order for a multi-stage Dockerfile that builds a static site and serves it with nginx.
Attempts:
2 left
💡 Hint
Start with the builder stage, then build, then switch to nginx stage and copy files.
✗ Incorrect
First define the builder stage (4), run build commands (1), then define nginx stage (2), and finally copy built files (3).
❓ Troubleshoot
advanced2:00remaining
Why does nginx serve a 404 error after multi-stage build?
You built a static site with a multi-stage Dockerfile but nginx returns 404 for all pages. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check where nginx expects static files to be located.
✗ Incorrect
nginx serves files from /usr/share/nginx/html by default. If files are copied elsewhere, nginx returns 404.
✅ Best Practice
expert3:00remaining
Optimizing multi-stage Dockerfile for smallest image size
Which practice best reduces the final image size when building a static site with multi-stage Dockerfile?
Attempts:
2 left
💡 Hint
Think about what is needed in the final image to serve static files only.
✗ Incorrect
Using a minimal base image like nginx:alpine keeps the final image small by excluding build tools and unnecessary files.