# Docker
Docker is a platform for developing, shipping, and running applications in containers—lightweight, isolated environments that package code with all dependencies. Created by [[Solomon Hykes]] at dotCloud (later Docker, Inc.) and released in 2013, Docker revolutionized software deployment by making containers accessible to developers. It became the de facto standard for containerization.
Unlike virtual machines that include full operating systems, Docker containers share the host kernel while maintaining isolation through Linux namespaces and cgroups. This makes containers fast to start (milliseconds vs minutes), efficient in resources, and consistent across environments ("works on my machine" solved). Docker's ecosystem includes Docker Hub (image registry), Docker Compose (multi-container apps), and Docker Desktop.
## Core Concepts
| Concept | Description |
|---------|-------------|
| **Image** | Read-only template with application and dependencies |
| **Container** | Running instance of an image |
| **Dockerfile** | Script defining how to build an image |
| **Registry** | Storage for images (Docker Hub, ECR, GCR) |
| **Volume** | Persistent storage for containers |
| **Network** | Virtual network connecting containers |
| **Compose** | Tool for multi-container applications |
## Architecture
```
┌─────────────────────────────────────────────────────┐
│ Docker Client │
│ (docker CLI) │
└────────────────────────┬────────────────────────────┘
│ REST API
┌────────────────────────▼────────────────────────────┐
│ Docker Daemon │
│ (dockerd) │
├─────────────────────────────────────────────────────┤
│ Images │ Containers │ Networks │ Volumes │
└────────────────────────┬────────────────────────────┘
│
┌────────────────────────▼────────────────────────────┐
│ Container Runtime (containerd) │
└────────────────────────┬────────────────────────────┘
│
┌────────────────────────▼────────────────────────────┐
│ Linux Kernel │
│ (namespaces, cgroups, OverlayFS) │
└─────────────────────────────────────────────────────┘
```
## Common Commands
```bash
# Run a container
docker run -d -p 8080:80 nginx
# List running containers
docker ps
# Build image from Dockerfile
docker build -t myapp:latest .
# View logs
docker logs -f container_name
# Execute command in container
docker exec -it container_name bash
# Stop and remove
docker stop container_name
docker rm container_name
# Manage images
docker images
docker pull nginx:latest
docker rmi image_name
# Clean up
docker system prune -a
```
## Dockerfile Example
```dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
```
## Docker Compose Example
```yaml
version: '3.8'
services:
web:
build: .
ports:
- "3000:3000"
depends_on:
- db
db:
image: postgres:15
volumes:
- pgdata:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: secret
volumes:
pgdata:
```
## Docker vs Virtual Machines
| Aspect | Docker Container | Virtual Machine |
|--------|------------------|-----------------|
| Startup | Seconds | Minutes |
| Size | MBs | GBs |
| Isolation | Process-level | Full OS |
| Performance | Near-native | Overhead |
| Density | 100s per host | 10s per host |
| Portability | High | Medium |
## Ecosystem
- **Docker Hub**: Public image registry (hub.docker.com)
- **Docker Desktop**: GUI for Mac/Windows
- **Docker Compose**: Multi-container orchestration
- **Docker Swarm**: Native clustering (largely replaced by Kubernetes)
- **BuildKit**: Modern image builder
## History
- **2013**: Docker open-sourced by dotCloud
- **2014**: Docker Hub launched; 1.0 released
- **2015**: Docker Compose released
- **2017**: Moby Project; containerd donated to CNCF
- **2019**: Docker Enterprise sold to Mirantis
- **Present**: Docker, Inc. focuses on developer tools
## References
- https://docker.com
- https://docs.docker.com
- https://hub.docker.com
- https://en.wikipedia.org/wiki/Docker_(software)
## Related
- [[Solomon Hykes]]
- [[Kubernetes]]
- [[Docker Desktop]]
- [[Docker Compose]]
- [[Docker Model Runner]]
- [[Docker MCP Catalog]]
- [[Containerization]]
- [[DevOps]]
- [[LazyDocker]]
- [[Podman]]
- [[containerd]]