What problem does Docker solve?
Imagine this scenario (which happens ALL the time):
| Situation | What you hear |
|---|---|
| Developer | "It works perfectly on my machine" |
| Production server | Error 500, crash, missing dependencies |
| New developer | "I've spent 2 days setting up the environment" |
| DevOps | "What Node version did you use? And Python?" |
Docker solves this by packaging your application WITH EVERYTHING it needs: code, runtime, libraries, configuration. If it works in Docker, it works anywhere.
๐ฅ๏ธ Virtual Machines vs Containers
VIRTUAL MACHINE CONTAINER (DOCKER)
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโ โโโโโโโโ โโโโโโโโ
โ App โ โ App1 โ โ App2 โ โ App3 โ
โโโโโโโโโโโโโโโโโโโค โโโโโโโโดโโดโโโโโโโดโโดโโโโโโโค
โ Libs/Binaries โ โ Libs/Binaries โ
โโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Guest OS โ โ Full OS โ Docker Engine โ
โ (Ubuntu 8GB) โ โ (~100MB) โ
โโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Hypervisor โ โ Host OS โ
โโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Host OS โ โ Hardware โ
โโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Hardware โ
โโโโโโโโโโโโโโโโโโโ
๐ข Heavy: 10-20 GB per VM ๐ Light: 100-500 MB
โฑ๏ธ Boot: 1-2 minutes โฑ๏ธ Boot: 1-2 seconds
๐ฆ Full isolation ๐ฆ Process-level isolation
๐ฐ Resource savings
| Metric | Traditional VM | Docker Container |
|---|---|---|
| RAM per instance | 1-8 GB | 50-500 MB |
| Disk | 10-40 GB | 100 MB - 2 GB |
| Startup time | 30s - 2min | 1-5 seconds |
| Apps per server | 5-10 VMs | 50-100+ containers |
| CPU overhead | 15-20% | 1-5% |
๐ก On a 32GB RAM server: you can run ~4 VMs or ~50 containers doing the same thing.
Why is it essential for the modern developer?
| Use | Benefit |
|---|---|
| Local development | Same environment as production |
| Onboarding | New dev productive in minutes, not days |
| CI/CD | Tests in identical environment to production |
| Microservices | Each service in its container |
| Experimenting | Try technologies without polluting your system |
| Scalability | Kubernetes orchestrates thousands of containers |
๐ง Docker alternatives
Docker popularized containers, but it's not the only option:
| Technology | Creator | Characteristics |
|---|---|---|
| Docker | Docker Inc | Most popular, Docker Hub, Docker Desktop |
| Podman | Red Hat | Daemonless, rootless, Docker CLI compatible |
| containerd | CNCF | Runtime used by Docker and Kubernetes |
| LXC/LXD | Canonical | System containers (more like VMs) |
| Colima | Open Source | Docker on macOS/Linux without Docker Desktop |
๐ก Tip: If you use Linux and want to avoid Docker Desktop, Podman is the most popular alternative. Commands are almost identical:
podman runinstead ofdocker run.
Key concepts
| Concept | What it is | Analogy |
|---|---|---|
| Image | Immutable template | Written recipe |
| Container | Instance of an image | Prepared dish |
| Dockerfile | Instructions to create image | Recipe steps |
| Registry | Image repository | Recipe library |
| Volume | Persistent data | Ingredients you save |
| Network | Communication between containers | Connection between kitchens |
Installation
| System | Recommended option | Lightweight alternative |
|---|---|---|
| macOS | brew install --cask docker | Colima + Docker CLI |
| Windows | Docker Desktop (WSL2) | Podman Desktop |
| Linux | Docker Engine | Podman (daemonless) |
# Verify installation
docker --version
docker run hello-world
Container lifecycle
Dockerfile docker build Image docker run Container
โโโโโโโโโโ โโโโโโโโโโโโโโโโโโถ โโโโโโโโ โโโโโโโโโโโโโโโโโโโโถ โโโโโโโโโโ
(recipe) (frozen (served)
dish)
docker push docker pull
โโโโโโโโโโโโถ Docker Hub โโโโโโโโโโโโโโโโโโโโ
(registry)
Your first container
# Test that Docker works
docker run hello-world
# Run Ubuntu interactively
docker run -it ubuntu bash
# Inside the container:
cat /etc/os-release # Ubuntu!
exit # Exit
Essential commands
# See running containers
docker ps
# See all containers
docker ps -a
# See downloaded images
docker images
# Run with interactive shell
docker run -it ubuntu bash
# Stop container
docker stop <container_id>
# Remove container
docker rm <container_id>
Practical example: Node.js
# Run Node.js 20
docker run -it node:20 node
# Now you can write JavaScript
> console.log("Hello from Docker!")
Your first Dockerfile
FROM node:20
WORKDIR /app
COPY . .
RUN npm install
CMD ["npm", "start"]
# Build image
docker build -t my-app .
# Run
docker run -p 3000:3000 my-app
Practice
โ Docker Hello World โ Your first container
Useful links
- ๐ Docker Docs
- ๐ Docker Getting Started