0
0
NextJSframework~20 mins

Docker deployment in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Docker Deployment Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will be the output when running this Dockerfile for a Next.js app?
Consider this Dockerfile for a Next.js app. What will be the final behavior when you run the container and visit the app in a browser?
NextJS
FROM node:18-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
AThe app runs in production mode on port 3000, serving the built Next.js app.
BThe app runs in development mode with hot reload on port 3000.
CThe container fails to start because the build step is missing.
DThe app runs but on port 80 instead of 3000.
Attempts:
2 left
💡 Hint
Check the CMD and EXPOSE instructions and what npm start does in Next.js.
📝 Syntax
intermediate
1:30remaining
Which Dockerfile snippet correctly copies only production dependencies for a Next.js app?
You want to optimize your Docker image by installing only production dependencies. Which snippet correctly does this?
ARUN npm install --prod
BRUN npm install --only=production
CRUN npm ci --only=production
DRUN npm install --production=true
Attempts:
2 left
💡 Hint
Check npm install flags for production-only installs.
🔧 Debug
advanced
2:30remaining
Why does this Docker container fail to serve the Next.js app after build?
Given this Dockerfile snippet, the container starts but the app shows a 404 error on all routes. What is the likely cause?
NextJS
FROM node:18-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["node", "server.js"]
APort 3000 is not exposed correctly, so the app is unreachable.
BThe build step failed silently, so no pages exist to serve.
CThe app uses Next.js default server, but CMD runs a non-existent server.js file causing 404.
DThe container lacks environment variables needed to run the app.
Attempts:
2 left
💡 Hint
Check the CMD instruction and whether server.js exists by default in Next.js.
lifecycle
advanced
2:00remaining
What is the effect of using multi-stage builds in Docker for Next.js deployment?
You use a multi-stage Dockerfile with a build stage and a final stage copying only the build output and node_modules. What benefit does this provide?
AIt automatically updates the app when source code changes.
BIt speeds up the build process by running all commands in one stage.
CIt allows hot reloading inside the container during development.
DIt reduces the final image size by excluding development dependencies and build tools.
Attempts:
2 left
💡 Hint
Think about what multi-stage builds do with intermediate files.
🧠 Conceptual
expert
3:00remaining
Which environment variable setup is best for configuring Next.js runtime behavior in Docker?
You want to configure Next.js to run in production mode and set a custom API URL inside a Docker container. Which approach is correct?
ASet environment variables in the Dockerfile using ENV, then access them in Next.js via process.env.
BHardcode variables in next.config.js and rebuild the image for each change.
CPass variables only at runtime with docker run -e but do not declare them in Dockerfile.
DUse a .env file inside the container without declaring ENV or passing variables.
Attempts:
2 left
💡 Hint
Consider how Next.js reads environment variables and Docker best practices.