Which reason best explains why developers create separate Dockerfiles for development and production environments?
Think about what features are useful during coding but not needed in production.
Development Dockerfiles often include tools like debuggers and live reload to help developers. Production Dockerfiles exclude these to keep images small and secure.
Given two Dockerfiles, one for development and one for production, which output shows the correct difference when running docker images after building both?
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"]
Consider that development images usually have more tools and dependencies.
The development image is larger because it includes all dependencies and tools for development. The production image is smaller because it installs only production dependencies.
Which Dockerfile snippet is best suited for a production environment to optimize image size and security?
Look for a lightweight base image and installation of only production dependencies.
Using a lightweight base like alpine and installing only production dependencies reduces image size and attack surface, ideal for production.
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"]
Check if the command used is available in production dependencies.
'npm run dev' usually requires development dependencies which are not installed with '--only=production', so the command fails.
Which multi-stage Dockerfile correctly separates development and production stages to optimize build time and image size?
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"]
Consider which stages include dev tools and which produce minimal production images.
Stage 3 includes full source and dev tools for development. Stage 2 copies only built files and installs production dependencies for a small production image.