Docker concepts
How Docker works: the client and daemon, images and layers, registries, networks, volumes and Compose
1. Client, daemon and containers
- docker CLI — The client: every docker command is a request to the daemon's API.
- dockerd — The daemon builds images, runs containers and manages networks and volumes.
- containerd — The runtime underneath that starts and stops the container processes.
- Container — A process isolated by namespaces and cgroups, sharing the host's kernel.
A container is a process on the host, not a small virtual machine.
2. Images and layers
- Image — A read-only template: a stack of layers plus settings such as the start command.
- Layer — Each Dockerfile instruction adds a layer; unchanged layers come from the build cache.
- Container layer — A thin writable layer on top, lost when the container is removed.
- Tag — A name for one image, such as nginx:1.27; latest is only a default name.
Order a Dockerfile from least to most often changed to keep the cache.
3. Registries
- Registry — A server that stores images: Docker Hub, Amazon ECR, GitHub Container Registry.
- Repository — One image's versions in a registry, told apart by tag.
- push and pull — push uploads your image's layers; pull downloads only the layers a host lacks.
- Digest — The sha256 of an image's content: pin it when you need exactly the same image.
4. Networking
- bridge — The default: containers on one host share a private network behind NAT.
- Your own bridge — Containers on it find each other by name through Docker's DNS.
- Publishing a port — -p 8080:80 sends the host's port 8080 to the container's port 80.
- host and none — host shares the host's network; none gives the container no network.
Create your own network so containers can call each other by name.
5. Volumes and bind mounts
- Volume — Storage Docker manages in its own area; it outlives the container.
- Bind mount — A host folder mounted into the container: handy for code while developing.
- tmpfs — Memory-only storage for scratch files, gone when the container stops.
- The rule — Data you must keep goes in a volume, never in the container's writable layer.
6. Docker Compose
- compose.yaml — One file describing the app's services, networks and volumes.
- Service — A container definition: image or build, ports, environment and volumes.
- Network — Compose puts the services on one network, so they reach each other by name.
- up and down — docker compose up starts everything; down stops and removes it.
One command brings up the whole app the same way on every machine.