Docker
Learn Docker in depth: how the engine and its runtimes fit together, running and inspecting containers, images and registries, writing Dockerfiles, BuildKit and multi-platform builds, storage, networking, Compose, container security, and running containers in production and CI.
Containers vs virtual machinesA VM virtualizes hardware and boots its own kernel. A container is a process on the host's kernel. What that costs, what it buys, and when you want both.The Docker architecture: client, daemon and runtimesWhat runs when you type docker run: the CLI, the Engine API, dockerd, containerd, the shim and runc, and why the work is split across five programs.The OCI standards: image, runtime and distributionThree Open Container Initiative specs define what an image is, how a runtime starts one and how registries serve it, which is why tools interoperate.Installing Docker Engine and Docker DesktopDocker Engine on a Linux server from Docker's apt repository, Docker Desktop on a laptop, what each one actually installs, and the post-install traps.Docker alternatives: Podman, nerdctl and friendsPodman, nerdctl, Colima, Rancher Desktop, OrbStack and Apple's container run the same OCI images. How each differs from Docker and when to pick one.docker run and the container lifecycleWhat docker run really does, the states a container moves through, how stop, kill and rm differ, and what an exit code like 137 is telling you.Interactive, detached and execWhat -i, -t and -d actually change, how attach differs from exec, how to leave a container without stopping it, and getting a shell into a running one.Configuring containers with environment variablesPassing settings with -e and --env-file, which value wins, the env-file format's surprises, and why environment variables are a poor place for secrets.Container logs and logging driversDocker captures what PID 1 writes to stdout and stderr. Reading it with docker logs, picking a logging driver, and stopping json-file from filling the disk.Inspecting containers: inspect, top, stats and eventsRead a container's config and state with docker inspect and Go templates, its processes with top, its live usage with stats and its history with events.Restart policies and health checksHow Docker restarts containers that exit, the back-off it uses, what a HEALTHCHECK reports, and why an unhealthy container is not restarted on its own.Cleaning up: prune and disk usageWhere Docker's disk space goes, how to measure it with docker system df, what each prune command removes and keeps, and the things df doesn't show.Image names: repositories, tags and digestsHow Docker reads a name like nginx:1.31 or ghcr.io/acme/api@sha256:…, which registry it really means, and when to pin a tag, a digest or both.Layers, overlayfs and copy-on-writeHow read-only image layers and a thin writable layer become one filesystem with overlayfs, what copy-up and whiteouts cost, and where it all lives on disk.Manifests, indexes and multi-platform imagesHow one tag serves amd64, arm64 and more: the image index, per-platform manifests, how a client picks one, and the attestation entries that ride along.Choosing a base imageFull, slim, Alpine, distroless, hardened or scratch: what each base image puts under your app and what it costs in size, compatibility and debugging.Docker Hub and other registriesWhat Docker Hub offers and limits, how to read its rate-limit headers, and the alternatives: GHCR, cloud registries, official-image mirrors, self-hosting.Tagging and pushing imagesdocker tag, login and push: what each does to your image, what goes over the wire, where credentials end up, and a tagging scheme that survives production.Running a private registrySelf-hosting images with the registry:3 image or Harbor: TLS, htpasswd auth, deleting and garbage-collecting, pull-through caching, and when not to bother.Dockerfile instructions, from FROM to CMDWhat each of the 18 Dockerfile instructions does, which ones change files and which only edit the image config, and the shell and exec forms.CMD, ENTRYPOINT and PID 1How CMD and ENTRYPOINT combine, why shell form makes docker stop hang for 10 seconds, and how exec, --init and STOPSIGNAL fix it.The build context and .dockerignoreWhat the build context is, why COPY . . can ship your .git and .env into an image, and how .dockerignore patterns, negation and ** really match.Layer caching and instruction orderHow BuildKit decides a step is cached: command text for RUN, file checksums for COPY, build args from first use. And why stale cache bites.Multi-stage buildsBuild with a full toolchain, ship only the result: named stages, COPY --from, --target for test and debug images, and how BuildKit skips unused stages.Build arguments and environment variablesARG is for the build and ENV is for the container. Scope rules, how ENV overrides ARG, and why an ARG secret ends up in docker history anyway.Linting Dockerfiles and build checksCatch Dockerfile mistakes before they ship: BuildKit's built-in build checks with docker build --check, the check directive, and hadolint in CI.BuildKit and docker buildxBuildKit is the engine behind docker build and buildx is its client. Frontends, LLB, builders and drivers, exporters, and when to create your own builder.Cache mounts and build secretsRUN --mount keeps package caches between builds without baking them into layers, and passes tokens and SSH keys to one step without leaking them.Multi-platform buildsBuild one image tag for amd64 and arm64: --platform, the three strategies (QEMU, native nodes, cross-compiling), and the BUILDPLATFORM pattern.Build caches in CICI runners start with an empty build cache. Export it with --cache-to and import it with --cache-from: registry, gha, inline and local backends, min vs max.Shrinking imagesMeasure first, then cut: smaller bases, multi-stage builds, no package caches, no duplicate layers from chmod and chown, and static binaries on scratch.The container filesystem is ephemeralFiles a container writes live in its writable layer: kept across restarts, deleted with docker rm and lost on every image upgrade. Where data goes instead.Named volumesCreate, mount, inspect and remove named volumes; how an empty volume is pre-filled from the image; and why Postgres 18 moved its volume path.Bind mounts and tmpfs mountsMap a host directory into a container for live code and config, or give it memory-only scratch space. Syntax differences, read-only mounts, and the traps.File ownership and permissions in mountsWhy containers hit Permission denied on mounted files: the kernel compares numeric UIDs, not names. Matching UIDs, --user, chown-then-drop entrypoints.Backing up and migrating volume dataBack up a volume with a throwaway tar container, restore it, stream it to another host over SSH, and know when a database dump beats copying files.The default bridge networkHow a container on docker0 gets an address, reaches the internet through NAT, and why the default bridge has no DNS and is not for production.User-defined networks and container DNSCreate your own bridge networks so containers find each other by name through Docker's DNS at 127.0.0.11, stay isolated from other stacks, and rewire live.Publishing ports and the host firewallWhat -p really does, why a published port ignores ufw, and how to keep databases private: bind to 127.0.0.1, filter in DOCKER-USER, publish one proxy.Host, none, macvlan and ipvlan networksThe network drivers that skip Docker's bridge: share the host's stack, have no network at all, or put containers straight on the LAN with their own addresses.Reaching the host and the outside worldWhy localhost in a container is the container, how host.docker.internal and host-gateway reach host services, and the proxy, DNS and MTU traps on the way out.Why Compose existsFive docker run commands, typed in the right order with the right flags, every time. Compose turns that into one declared, versioned project.The Compose file: services, networks and volumesHow compose.yaml is laid out: services, networks and volumes, short and long syntax, isolated networks, external resources, and reuse with x- blocks.Startup order: depends_on and health checksdepends_on orders container creation, not readiness. Health checks, service_healthy, one-shot migrations and why your app must still retry.Variables, env files and profilesOne Compose file, many machines: ${VAR} interpolation, the .env file versus env_file, which value wins, and profiles for optional services.Compose for development: watch, overrides and includeA fast inner loop with Compose: override files and merge rules, !reset and !override, include for shared stacks, and compose watch to sync code.Compose in production and its limitsRunning Compose on one server for real: a production overlay, pinned images, restarts, log rotation and deploys, and the signs you have outgrown it.Container isolation and its limitsWhat Docker actually puts around a container by default, why one shared kernel is the real boundary, and when you need gVisor or a microVM instead.The Docker socket is rootWhy access to /var/run/docker.sock, or the docker group, equals root on the host, why read-only mounts don't help, and safer ways to give tools access.Running as non-root and rootless DockerThree ways to take root away: a non-root USER in the image, user-namespace remapping, and rootless Docker, where even the daemon is an ordinary user.Capabilities, seccomp and read-only containersShrink what a container can do: drop capabilities, block privilege gain, keep or tighten the seccomp profile, and make the root filesystem read-only.Secrets at build time and run timeHow secrets leak into images through ARG, ENV and deleted files, why environment variables are a weak place for them, and how Compose mounts secrets as files.Scanning images for vulnerabilitiesHow image scanners turn a package list into CVE reports, why most findings have no fix, and how to gate CI on the ones that matter with Scout, Trivy or Grype.Signing and verifying imagesSignatures prove who built an image digest. How Sigstore keyless signing works, what a real cosign signature contains, and how to verify before you deploy.Resource limits for memory, CPU and PIDsContainers have no limits by default. How --memory, --cpus, --cpu-shares and --pids-limit map to cgroups, what an OOM kill looks like, and CPU throttling.Debugging a running containerA method for broken containers: read state, exit codes and logs first, then get inside with exec, docker debug, a namespace-sharing sidecar or nsenter.Monitoring containersWhat to watch on a Docker host and where the numbers come from: docker stats, the Engine API, events, cAdvisor, Prometheus and Grafana, and alerts.Docker in CI pipelinesHow a CI job gets a Docker engine (socket, Docker-in-Docker, hosted VMs, remote builders), and a pipeline that tests, tags, pushes and signs images.Docker contexts and remote enginesDrive Docker engines on other machines from your own CLI: contexts over SSH or TLS, how the CLI picks an endpoint, and what changes when the engine is remote.
What Docker is
- Containers vs virtual machinesA VM virtualizes hardware and boots its own kernel. A container is a process on the host's kernel. What that costs, what it buys, and when you want both.
- The Docker architecture: client, daemon and runtimesWhat runs when you type docker run: the CLI, the Engine API, dockerd, containerd, the shim and runc, and why the work is split across five programs.
- The OCI standards: image, runtime and distributionThree Open Container Initiative specs define what an image is, how a runtime starts one and how registries serve it, which is why tools interoperate.
- Installing Docker Engine and Docker DesktopDocker Engine on a Linux server from Docker's apt repository, Docker Desktop on a laptop, what each one actually installs, and the post-install traps.
- Docker alternatives: Podman, nerdctl and friendsPodman, nerdctl, Colima, Rancher Desktop, OrbStack and Apple's container run the same OCI images. How each differs from Docker and when to pick one.
Running containers
- docker run and the container lifecycleWhat docker run really does, the states a container moves through, how stop, kill and rm differ, and what an exit code like 137 is telling you.
- Interactive, detached and execWhat -i, -t and -d actually change, how attach differs from exec, how to leave a container without stopping it, and getting a shell into a running one.
- Configuring containers with environment variablesPassing settings with -e and --env-file, which value wins, the env-file format's surprises, and why environment variables are a poor place for secrets.
- Container logs and logging driversDocker captures what PID 1 writes to stdout and stderr. Reading it with docker logs, picking a logging driver, and stopping json-file from filling the disk.
- Inspecting containers: inspect, top, stats and eventsRead a container's config and state with docker inspect and Go templates, its processes with top, its live usage with stats and its history with events.
- Restart policies and health checksHow Docker restarts containers that exit, the back-off it uses, what a HEALTHCHECK reports, and why an unhealthy container is not restarted on its own.
- Cleaning up: prune and disk usageWhere Docker's disk space goes, how to measure it with docker system df, what each prune command removes and keeps, and the things df doesn't show.
Images and registries
- Image names: repositories, tags and digestsHow Docker reads a name like nginx:1.31 or ghcr.io/acme/api@sha256:…, which registry it really means, and when to pin a tag, a digest or both.
- Layers, overlayfs and copy-on-writeHow read-only image layers and a thin writable layer become one filesystem with overlayfs, what copy-up and whiteouts cost, and where it all lives on disk.
- Manifests, indexes and multi-platform imagesHow one tag serves amd64, arm64 and more: the image index, per-platform manifests, how a client picks one, and the attestation entries that ride along.
- Choosing a base imageFull, slim, Alpine, distroless, hardened or scratch: what each base image puts under your app and what it costs in size, compatibility and debugging.
- Docker Hub and other registriesWhat Docker Hub offers and limits, how to read its rate-limit headers, and the alternatives: GHCR, cloud registries, official-image mirrors, self-hosting.
- Tagging and pushing imagesdocker tag, login and push: what each does to your image, what goes over the wire, where credentials end up, and a tagging scheme that survives production.
- Running a private registrySelf-hosting images with the registry:3 image or Harbor: TLS, htpasswd auth, deleting and garbage-collecting, pull-through caching, and when not to bother.
Writing Dockerfiles
- Dockerfile instructions, from FROM to CMDWhat each of the 18 Dockerfile instructions does, which ones change files and which only edit the image config, and the shell and exec forms.
- CMD, ENTRYPOINT and PID 1How CMD and ENTRYPOINT combine, why shell form makes docker stop hang for 10 seconds, and how exec, --init and STOPSIGNAL fix it.
- The build context and .dockerignoreWhat the build context is, why COPY . . can ship your .git and .env into an image, and how .dockerignore patterns, negation and ** really match.
- Layer caching and instruction orderHow BuildKit decides a step is cached: command text for RUN, file checksums for COPY, build args from first use. And why stale cache bites.
- Multi-stage buildsBuild with a full toolchain, ship only the result: named stages, COPY --from, --target for test and debug images, and how BuildKit skips unused stages.
- Build arguments and environment variablesARG is for the build and ENV is for the container. Scope rules, how ENV overrides ARG, and why an ARG secret ends up in docker history anyway.
- Linting Dockerfiles and build checksCatch Dockerfile mistakes before they ship: BuildKit's built-in build checks with docker build --check, the check directive, and hadolint in CI.
BuildKit and advanced builds
- BuildKit and docker buildxBuildKit is the engine behind docker build and buildx is its client. Frontends, LLB, builders and drivers, exporters, and when to create your own builder.
- Cache mounts and build secretsRUN --mount keeps package caches between builds without baking them into layers, and passes tokens and SSH keys to one step without leaking them.
- Multi-platform buildsBuild one image tag for amd64 and arm64: --platform, the three strategies (QEMU, native nodes, cross-compiling), and the BUILDPLATFORM pattern.
- Build caches in CICI runners start with an empty build cache. Export it with --cache-to and import it with --cache-from: registry, gha, inline and local backends, min vs max.
- Shrinking imagesMeasure first, then cut: smaller bases, multi-stage builds, no package caches, no duplicate layers from chmod and chown, and static binaries on scratch.
Storage and data
- The container filesystem is ephemeralFiles a container writes live in its writable layer: kept across restarts, deleted with docker rm and lost on every image upgrade. Where data goes instead.
- Named volumesCreate, mount, inspect and remove named volumes; how an empty volume is pre-filled from the image; and why Postgres 18 moved its volume path.
- Bind mounts and tmpfs mountsMap a host directory into a container for live code and config, or give it memory-only scratch space. Syntax differences, read-only mounts, and the traps.
- File ownership and permissions in mountsWhy containers hit Permission denied on mounted files: the kernel compares numeric UIDs, not names. Matching UIDs, --user, chown-then-drop entrypoints.
- Backing up and migrating volume dataBack up a volume with a throwaway tar container, restore it, stream it to another host over SSH, and know when a database dump beats copying files.
Networking
- The default bridge networkHow a container on docker0 gets an address, reaches the internet through NAT, and why the default bridge has no DNS and is not for production.
- User-defined networks and container DNSCreate your own bridge networks so containers find each other by name through Docker's DNS at 127.0.0.11, stay isolated from other stacks, and rewire live.
- Publishing ports and the host firewallWhat -p really does, why a published port ignores ufw, and how to keep databases private: bind to 127.0.0.1, filter in DOCKER-USER, publish one proxy.
- Host, none, macvlan and ipvlan networksThe network drivers that skip Docker's bridge: share the host's stack, have no network at all, or put containers straight on the LAN with their own addresses.
- Reaching the host and the outside worldWhy localhost in a container is the container, how host.docker.internal and host-gateway reach host services, and the proxy, DNS and MTU traps on the way out.
Docker Compose
- Why Compose existsFive docker run commands, typed in the right order with the right flags, every time. Compose turns that into one declared, versioned project.
- The Compose file: services, networks and volumesHow compose.yaml is laid out: services, networks and volumes, short and long syntax, isolated networks, external resources, and reuse with x- blocks.
- Startup order: depends_on and health checksdepends_on orders container creation, not readiness. Health checks, service_healthy, one-shot migrations and why your app must still retry.
- Variables, env files and profilesOne Compose file, many machines: ${VAR} interpolation, the .env file versus env_file, which value wins, and profiles for optional services.
- Compose for development: watch, overrides and includeA fast inner loop with Compose: override files and merge rules, !reset and !override, include for shared stacks, and compose watch to sync code.
- Compose in production and its limitsRunning Compose on one server for real: a production overlay, pinned images, restarts, log rotation and deploys, and the signs you have outgrown it.
Container security
- Container isolation and its limitsWhat Docker actually puts around a container by default, why one shared kernel is the real boundary, and when you need gVisor or a microVM instead.
- The Docker socket is rootWhy access to /var/run/docker.sock, or the docker group, equals root on the host, why read-only mounts don't help, and safer ways to give tools access.
- Running as non-root and rootless DockerThree ways to take root away: a non-root USER in the image, user-namespace remapping, and rootless Docker, where even the daemon is an ordinary user.
- Capabilities, seccomp and read-only containersShrink what a container can do: drop capabilities, block privilege gain, keep or tighten the seccomp profile, and make the root filesystem read-only.
- Secrets at build time and run timeHow secrets leak into images through ARG, ENV and deleted files, why environment variables are a weak place for them, and how Compose mounts secrets as files.
- Scanning images for vulnerabilitiesHow image scanners turn a package list into CVE reports, why most findings have no fix, and how to gate CI on the ones that matter with Scout, Trivy or Grype.
- Signing and verifying imagesSignatures prove who built an image digest. How Sigstore keyless signing works, what a real cosign signature contains, and how to verify before you deploy.
Production and operations
- Resource limits for memory, CPU and PIDsContainers have no limits by default. How --memory, --cpus, --cpu-shares and --pids-limit map to cgroups, what an OOM kill looks like, and CPU throttling.
- Debugging a running containerA method for broken containers: read state, exit codes and logs first, then get inside with exec, docker debug, a namespace-sharing sidecar or nsenter.
- Monitoring containersWhat to watch on a Docker host and where the numbers come from: docker stats, the Engine API, events, cAdvisor, Prometheus and Grafana, and alerts.
- Docker in CI pipelinesHow a CI job gets a Docker engine (socket, Docker-in-Docker, hosted VMs, remote builders), and a pipeline that tests, tags, pushes and signs images.
- Docker contexts and remote enginesDrive Docker engines on other machines from your own CLI: contexts over SSH or TLS, how the CLI picks an endpoint, and what changes when the engine is remote.