Docker
A platform for developing, shipping, and running applications inside lightweight, portable containers.
Detailed Explanation
Docker standardizes the application environment by bundling the code, runtime, libraries, and dependencies into a single 'image'. This ensures that the application runs identically on a developer's laptop, a staging server, or a production cloud environment. It has revolutionized DevOps by eliminating the 'it works on my machine' problem and enabling rapid scaling.
Quick Summary
Docker packages an application and its dependencies into a portable image that runs identically on any machine with a Docker runtime. It made containers mainstream and is the standard build artifact for cloud deployments.
Key Takeaways
- An image is the immutable blueprint; a container is a running instance of that image with its own filesystem and process tree.
- Dockerfiles define how an image is built, layer by layer, cached by content hash for fast rebuilds.
- Multi-stage builds separate build-time dependencies from runtime images, producing small, secure final artifacts.
- Docker uses Linux kernel features (namespaces, cgroups); on macOS and Windows it runs a hidden Linux VM.
- Best practice: pin base image versions, run as a non-root user, and minimize layers for security and size.
When to use it
- Reproducible local development environments that mirror production.
- CI/CD pipelines where every build produces an immutable, deployable artifact.
- Microservices, each shipped as its own image and orchestrated by Kubernetes or ECS.
- Packaging CLI tools or one-off scripts so users do not need the right language runtime installed.
Common Mistakes
- Using `latest` tags in production, breaks reproducibility when the upstream image is updated.
- Running containers as root by default, expanding the blast radius if the app is compromised.
- Putting secrets in environment variables baked into the image instead of injecting them at runtime.
- Ignoring image size; a 2 GB image slows every deploy, scale-up, and cold start.
Docker, Frequently Asked
Docker vs. virtual machine, what's the difference?
A VM virtualizes hardware and runs a full guest OS; a Docker container shares the host kernel and only isolates user space. Containers start in milliseconds and use tens of megabytes of RAM where a VM uses hundreds.
Do I need Docker if I am deploying to a managed platform?
Often yes, Vercel, Render, Fly, and most container platforms accept either a Dockerfile or a buildpack. Owning the Dockerfile gives you control over the runtime; relying on buildpacks gives you convenience but less reproducibility.
Is Docker still relevant with Kubernetes?
Yes. Kubernetes orchestrates containers; Docker (or Buildah/Kaniko) builds the images Kubernetes runs. They solve different problems and are usually used together.