Docker packages an application together with its dependencies into an image, then runs that
image as an isolated process on a shared kernel. Unlike a virtual machine, there is no guest
operating system — which is why a container starts in milliseconds and costs megabytes rather
than gigabytes.
┌──────────────────────────────┐ ┌──────────────────────────────┐
│ Virtual Machines │ │ Containers │
├──────────────────────────────┤ ├──────────────────────────────┤
│ App A │ App B │ │ App A │ App B │
│ Bins/Lib │ Bins/Lib │ │ Bins/Lib │ Bins/Lib │
│ Guest OS │ Guest OS │ ├───────────┴──────────────────┤
├───────────┴──────────────────┤ │ Container runtime │
│ Hypervisor │ ├──────────────────────────────┤
├──────────────────────────────┤ │ Host OS (shared kernel) │
│ Host OS │ ├──────────────────────────────┤
├──────────────────────────────┤ │ Hardware │
│ Hardware │ └──────────────────────────────┘
└──────────────────────────────┘
The shared kernel is also the main caveat: containers isolate processes, not kernels. A
Linux container needs a Linux kernel, which is why Docker Desktop runs a VM on Windows and
macOS, and why Windows containers are a separate thing entirely.
Core Concepts
Term
What it is
Image
A read-only, layered filesystem plus metadata. Built from a Dockerfile.
Container
A running instance of an image, with a thin writable layer on top.
Volume
Storage managed by Docker that outlives the container.
Network
A virtual network containers attach to in order to reach each other.
Registry
Where images are stored and distributed — Docker Hub, GHCR, Harbor.
Dockerfile
The recipe an image is built from.
Compose
A file format and CLI for running a multi-container application.
# Container management
docker run <image> # Run a container
docker ps # List running containers
docker ps -a # List all containers
docker stop <container> # Stop a container
docker start <container> # Start a stopped container
docker restart <container> # Restart a container
docker rm <container> # Remove a container
docker exec -it <container> bash # Execute a command in a container
# Image management
docker images # List images
docker pull <image> # Pull an image from a registry
docker build -t <name> . # Build an image from a Dockerfile
docker rmi <image> # Remove an image
docker tag <image> <new-name> # Tag an image
# System management
docker info # Display system information
docker version # Show Docker version
docker system df # Show disk usage
docker system prune # Remove unused data
docker logs <container> # View container logs
Common Docker Run Options
# Background execution
docker run -d <image>
# Port mapping — bind to localhost unless it must be public
docker run -p 127.0.0.1:8080:80 <image>
# Named volume (preferred for application data)
docker run -v myvolume:/data <image>
# Bind mount
docker run -v /host/path:/container/path <image>
# Environment variables
docker run -e VAR_NAME=value <image>
# Interactive terminal
docker run -it <image> /bin/bash
# Remove container on exit
docker run --rm <image>
# Set container name
docker run --name my-container <image>
# Limit resources
docker run --memory=512m --cpus=1 <image>
Docker Compose Quick Commands
# Start services
docker compose up
# Start in background
docker compose up -d
# Stop services
docker compose down
# View logs
docker compose logs -f
# Rebuild images
docker compose up --build
# Scale a service
docker compose up -d --scale web=3
Note
Compose v2 is invoked as docker compose, not docker-compose. The hyphenated v1 binary
is end-of-life and is not installed by current packages.