What is Docker?
Docker is an open-source platform that automates the deployment, scaling, and management of applications using containerization. Containers package an application and all its dependencies into a standardized unit, ensuring it runs the same way on any machine — from your laptop to production servers.
Why Docker?
- Consistency: "Works on my machine" is no longer a problem — containers run identically everywhere
- Isolation: Each container runs in its own environment, preventing dependency conflicts
- Portability: Move containers between development, staging, and production effortlessly
- Efficiency: Containers share the host OS kernel and use far fewer resources than virtual machines
- Speed: Containers start in seconds, making development and deployment much faster
Containers vs Virtual Machines
While virtual machines (VMs) include a full guest operating system, containers share the host OS kernel and only package the application and its dependencies. This makes containers significantly lighter and faster.
Comparison
| Feature | Container | Virtual Machine |
|---|---|---|
| Startup Time | Seconds | Minutes |
| Size | MBs | GBs |
| OS | Shares host kernel | Full guest OS |
| Isolation | Process-level | Full isolation |
| Performance | Near-native | Overhead from hypervisor |
Docker Architecture
Docker uses a client-server architecture with these key components:
- Docker Daemon (dockerd): Runs on the host and manages containers, images, networks, and volumes
- Docker Client (docker): The CLI tool you use to interact with the daemon
- Docker Registry: A repository for Docker images (e.g., Docker Hub)
- Docker Images: Read-only templates used to create containers
- Docker Containers: Running instances of images
Installing Docker
macOS
# Install Docker Desktop for macOS
# Download from https://www.docker.com/products/docker-desktop/
# Or use Homebrew:
brew install --cask docker
Linux (Ubuntu/Debian)
# Update packages
sudo apt-get update
# Install dependencies
sudo apt-get install ca-certificates curl gnupg
# Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Set up the repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Windows
# Install Docker Desktop for Windows
# Download from https://www.docker.com/products/docker-desktop/
# Requires WSL 2 backend
wsl --install
Verify Installation
# Check Docker version
docker --version
# Docker version 27.x.x, build xxxxx
# Run a test container
docker run hello-world
# Check Docker info
docker info
Your First Container
# Pull and run an nginx web server
docker run -d -p 8080:80 --name my-web nginx
# Visit http://localhost:8080 in your browser!
# See running containers
docker ps
# Stop the container
docker stop my-web
# Remove the container
docker rm my-web
Key Takeaways
- ✅ Docker packages apps into portable, isolated containers
- ✅ Containers are lighter and faster than VMs
- ✅ Docker ensures consistency across all environments
- ✅ The Docker ecosystem includes images, containers, registries, and orchestration tools