Docker is the most widely used platform for building, packaging, and running containers — lightweight, portable execution environments that bundle an application together with all its dependencies (code, runtime, libraries, config files). A Dockerfile defines the exact steps to build an image; that image can then be run as a container on any machine with Docker installed, eliminating the classic 'it works on my machine' problem. Docker images are stored in registries (Docker Hub, Amazon ECR, Azure Container Registry, Google Artifact Registry). In production, individual Docker containers are typically orchestrated at scale by Kubernetes. Key concepts to understand: images are read-only templates; containers are running instances of images; layers make images efficient by reusing unchanged steps; and multi-stage builds keep final images small and secure by excluding build-time dependencies. When would you use Docker? Use Docker whenever you want consistent, reproducible environments: packaging microservices for deployment, standardizing developer environments, running CI/CD pipelines in isolated environments, migrating legacy applications to cloud-native infrastructure, or bundling scripts and tools with their exact runtime dependencies. If you're deploying to ECS, EKS, or Kubernetes, Docker images are required — they are the deployable unit. Common mistakes: running containers as root (always specify a non-root USER in the Dockerfile for security), using 'latest' image tags in production (pin to a specific version or digest for reproducible deployments), building bloated images by copying the entire build environment into the final image (use multi-stage builds to separate build-time from runtime dependencies), and committing secrets or credentials into Docker images — use environment variables or secrets managers instead.
Example: A development team writes a Dockerfile that installs Node.js, copies the app code, and sets the startup command. Every developer runs the same image locally, the CI pipeline builds and tests it automatically, and the same image is deployed to production Kubernetes — guaranteeing identical behavior at every stage. Architecture use case: a multi-service e-commerce platform runs its frontend, API, payment service, and email worker as separate Docker containers — each independently deployable, scalable, and versioned through its own Docker image in Amazon ECR.
Category: containers
Difficulty: intermediate