Docker packages applications with their dependencies into containers — lightweight, isolated environments that run consistently anywhere.
Dockerfile defines the container image: FROM node:20-alpine, WORKDIR /app, COPY . ., RUN npm install, EXPOSE 3000, CMD ["npm", "start"]. Multi-stage builds reduce image size by separating build and runtime.
docker-compose.yml defines multi-container apps: services, networks, and volumes. docker compose up starts everything. Essential for dev environments with databases and caches.
Best practices: use specific base image tags (not latest), minimize layers, use .dockerignore, run as non-root user, and scan images with docker scout.
Container orchestration: Docker Swarm for simple clusters, Kubernetes for complex deployments. Managed services: AWS ECS, Google Cloud Run, Azure Container Apps.
Debugging: docker logs, docker exec -it container_name sh for interactive shell, docker stats for resource monitoring.