0
0
Nginxdevops~20 mins

Multi-stage builds for static sites in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multi-stage 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 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
AAn image named 'node' with the source code and node_modules installed
BAn image named 'nginx' with the static site files in /usr/share/nginx/html
CTwo images: one for 'node' builder and one for 'nginx' with static files
DNo images created because multi-stage builds do not produce images
Attempts:
2 left
💡 Hint
Think about what the final stage in a multi-stage build produces as the image.
Configuration
intermediate
1: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?
ACOPY --from=nginx /app/dist /usr/share/nginx/html
BCOPY /app/dist /usr/share/nginx/html
CCOPY --from=builder /app/dist /usr/share/nginx/html
DCOPY --from=builder /usr/share/nginx/html /app/dist
Attempts:
2 left
💡 Hint
Remember to specify the source stage and correct source and destination paths.
🔀 Workflow
advanced
2: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.
A4,1,2,3
B4,2,1,3
C2,4,1,3
D1,4,2,3
Attempts:
2 left
💡 Hint
Start with the builder stage, then build, then switch to nginx stage and copy files.
Troubleshoot
advanced
2: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?
AThe COPY command copied files to the wrong directory inside nginx image
BThe builder stage failed to run npm install
Cnginx image does not support static files
DThe Dockerfile is missing the EXPOSE 80 instruction
Attempts:
2 left
💡 Hint
Check where nginx expects static files to be located.
Best Practice
expert
3: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?
ARun npm install in the final stage instead of builder stage
BInstall all build tools in the final nginx image
CCopy node_modules folder to the final image for caching
DUse a minimal base image like nginx:alpine for the final stage
Attempts:
2 left
💡 Hint
Think about what is needed in the final image to serve static files only.