0
0
Dockerdevops~20 mins

Development vs production Dockerfiles - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dockerfile Mastery: Development vs Production
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use separate Dockerfiles for development and production?

Which reason best explains why developers create separate Dockerfiles for development and production environments?

ATo use the same image for both environments without any changes.
BTo include debugging tools and live reload features only in development images.
CTo ensure production images always contain source code for easier debugging.
DTo reduce the size of the development image by removing unnecessary tools.
Attempts:
2 left
💡 Hint

Think about what features are useful during coding but not needed in production.

💻 Command Output
intermediate
2:00remaining
Output difference between development and production Docker images

Given two Dockerfiles, one for development and one for production, which output shows the correct difference when running docker images after building both?

Docker
Dockerfile.dev:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]

Dockerfile.prod:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
CMD ["node", "server.js"]
A
REPOSITORY          TAG       SIZE
myapp               dev       800MB
myapp               prod      800MB
B
REPOSITORY          TAG       SIZE
myapp               prod      800MB
myapp               dev       400MB
C
REPOSITORY          TAG       SIZE
myapp               dev       400MB
myapp               prod      400MB
D
REPOSITORY          TAG       SIZE
myapp               dev       800MB
myapp               prod      400MB
Attempts:
2 left
💡 Hint

Consider that development images usually have more tools and dependencies.

Configuration
advanced
2:00remaining
Identify the production Dockerfile snippet

Which Dockerfile snippet is best suited for a production environment to optimize image size and security?

A
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
CMD ["node", "server.js"]
B
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]
C
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
CMD ["npm", "start"]
D
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install --production=false
COPY . .
CMD ["node", "server.js"]
Attempts:
2 left
💡 Hint

Look for a lightweight base image and installation of only production dependencies.

Troubleshoot
advanced
2:00remaining
Why does the production container fail to start?

A production Docker container built with this Dockerfile fails immediately after starting. What is the most likely cause?

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
CMD ["npm", "run", "dev"]
ACOPY commands are in the wrong order, so source code is missing.
BThe base image node:18-alpine does not support npm commands.
CThe command 'npm run dev' is missing in production dependencies, causing failure.
DThe WORKDIR is not set, so the command runs in the wrong directory.
Attempts:
2 left
💡 Hint

Check if the command used is available in production dependencies.

Best Practice
expert
3:00remaining
Choose the best multi-stage Dockerfile for development and production

Which multi-stage Dockerfile correctly separates development and production stages to optimize build time and image size?

Docker
Stage 1: Build
FROM node:18 AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

Stage 2: Production
FROM node:18-alpine
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY package*.json ./
RUN npm ci --only=production
CMD ["node", "dist/server.js"]

Stage 3: Development
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
CMD ["npm", "run", "dev"]
AUse Stage 3 for development and Stage 2 for production.
BUse Stage 1 for development and Stage 2 for production.
CUse Stage 2 for development and Stage 1 for production.
DUse Stage 3 for production and Stage 1 for development.
Attempts:
2 left
💡 Hint

Consider which stages include dev tools and which produce minimal production images.