🐳 Docker Build Instructions Quiz

Test your understanding of Dockerfile instructions and container configuration!

Docker Basic Foundation

Node.js Dockerfile

# Use Node.js slim image for smaller size
FROM node:18-slim

# Set working directory
WORKDIR /usr/src/app

# Copy package files for dependency caching
COPY package*.json ./

# Install production dependencies only
RUN npm ci --only=production

# Copy application code
COPY . .

# Set environment variables
ENV NODE_ENV=production \
    PORT=3000

# Expose application port
EXPOSE 3000

# Start application
CMD ["node", "server.js"]

Key Features:

  • Uses slim variant for optimized size
  • Leverages layer caching for faster builds
  • Production-optimized with npm ci
  • Clear environment configuration
  • Standard port exposure

Python Dockerfile

# Use Python slim image for smaller size
FROM python:3.11-slim

# Set working directory
WORKDIR /app

# Copy requirements for dependency caching
COPY requirements.txt .

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PORT=5000

# Expose application port
EXPOSE 5000

# Start application
CMD ["python", "app.py"]

Key Features:

  • Slim Python base for minimal image size
  • Optimized pip installation
  • Python-specific environment setup
  • Standard port configuration
  • Simple startup command