DevOps & Tools
Package, run and ship apps in containers: images, volumes, networking, Compose, security and deployment.
A practical path from what a container is to running containers in production. It covers the Linux features underneath, building lean Dockerfiles, persisting data, registries, Compose, networking, security hardening and the day-to-day developer workflow, ending with orchestration choices. Suited to developers who want to containerise their own apps. Each subject links the official documentation.
The subjects follow the roadmap.sh Docker roadmap.
Docker packages an application with its runtime, libraries and config into an image, then runs that image as an isolated process called a container. The same image behaves the same on a laptop, a CI runner and a production host, which is the whole point.
A container is an ordinary Linux process started with its own view of the filesystem, network, process tree and users, plus limits on CPU and memory. There is no guest kernel: every container shares the host kernel.
They end "works on my machine": dependencies ship inside the image, environments become reproducible, many apps with conflicting versions share one host, and deploys turn into "pull this image tag and start it".
Bare metal gives full performance but one environment per machine. VMs virtualise hardware and boot a whole guest OS, giving strong isolation at the cost of size and boot time. Containers isolate at the kernel level, start in milliseconds and are megabytes, but share the host kernel.
The Open Container Initiative standardises the image format, the runtime spec and the distribution API. Images built by Docker run under Podman, containerd or Kubernetes, and runc is the reference runtime Docker itself uses underneath.
Almost every image is a small Linux userland, so Dockerfiles are mostly shell commands run against Debian, Ubuntu or Alpine. Being comfortable at a Linux prompt makes writing and debugging images far easier.
Debian-based images use apt-get, Alpine uses apk, Red Hat family images use dnf. In a Dockerfile, update and install in one RUN, pass --no-install-recommends and clean the cache in the same layer.
Containers run as root by default. Create an unprivileged user, switch to it with USER, and make sure files it needs are owned correctly (COPY --chown). Bind-mounted files keep their numeric UID/GID from the host, a common source of permission errors.
Navigating with ls, cd and cat, inspecting processes with ps, finding things with grep and find, and editing permissions are what you do inside a running container with docker exec -it <name> sh.
Entrypoint scripts set up config then exec "$@" so the app becomes PID 1 and receives signals. Use set -eu, quote variables, and remember slim images often ship sh (dash or BusyBox) rather than bash.
Docker is a packaging tool, so you need something to package. A small web app with a database is the classic first project because it exercises images, networking, volumes and Compose at once.
Each runtime has its own containerising habits: Node needs npm ci and a lockfile, Python wants a virtualenv or wheel cache, Go compiles to a static binary that fits in a scratch or distroless image.
Containers fit stateless processes that read config from environment variables, log to stdout and keep state in external services. Splitting a system into one process per container makes scaling and replacing parts simple.
Containers are built from Linux kernel features, not magic: namespaces decide what a process can see, cgroups decide how much it can use, and a layered filesystem gives each container a cheap private root. Knowing the basics explains most odd behaviour.
PID, network, mount, UTS, IPC, user and cgroup namespaces each give a process a private copy of one kernel resource. That is why a container sees itself as PID 1 with its own hostname and network interfaces.
Control groups meter and cap CPU, memory, I/O and process counts for a group of processes. Docker flags like --memory, --cpus and --pids-limit write cgroup settings; exceeding a memory limit gets the container OOM-killed.
Image layers are read-only directories stacked by OverlayFS, with a thin writable layer on top for each container. Changing a file copies it up into that layer, so heavy writes belong on volumes instead.
On Linux you install Docker Engine directly; on macOS and Windows containers need a Linux VM, which Docker Desktop manages for you. Check the install with docker version and docker run hello-world.
A desktop app bundling the engine in a lightweight VM with the CLI, Compose, BuildKit and a GUI. Larger companies need a paid subscription; alternatives include Colima, OrbStack and Podman Desktop.
Install from Docker's own apt or dnf repository rather than the distro's older package. Adding your user to the docker group avoids sudo but is equivalent to root access; rootless mode is the safer option.
The core loop: pull or build an image, run a container from it, inspect it with docker ps and docker logs, then stop and remove it. Images are immutable templates; containers are their running, disposable instances, managed by the dockerd daemon behind the CLI.
Anything written inside a container disappears when the container is removed. Data that must outlive it goes into a named volume or a bind mount; temporary scratch data can go in a tmpfs mount kept in memory.
Each container gets a writable layer on top of its image. It survives restarts but is deleted with docker rm, is slower than a volume, and is never shared, so treat it as throwaway.
Named volumes are storage managed by Docker (docker volume create, -v data:/var/lib/postgresql/data). They persist across containers, are pre-filled from the image on first use, and are the right home for database files.
Mount a host path straight into a container, e.g. -v "$PWD":/app. Ideal for live code in development, but they depend on the host layout, inherit host permissions and are slow on Docker Desktop for large trees.
Before writing your own images, run other people's: Docker Hub has official images for databases, languages and tools. Prefer Docker Official Images or verified publishers, pin a version tag, and read the image page for its environment variables and volumes.
Run Postgres, MySQL or Redis locally in one command instead of installing them: set the password through env vars, publish the port and mount a named volume for the data directory.
Use images as disposable tools: docker run --rm -it -v "$PWD":/work -w /work <image> <cmd> runs a linter, a CLI or a specific language version without installing anything on the host.
A registry stores and serves images over the OCI distribution API. You docker login, docker push a tagged image and docker pull it on another machine; private registries add access control and scanning.
Docker's public registry and the default when an image name has no host. Free accounts get public repositories and a limited number of private ones; anonymous and free pulls are rate-limited, which can bite CI pipelines.
Tag with an immutable version or git SHA and deploy that, not latest. For reproducible pulls, reference the digest (image@sha256:…). Use semver tags like 1, 1.4, 1.4.2 so consumers choose how much to float.
GitHub Container Registry suits repos already on GitHub; AWS ECR, Google Artifact Registry and Azure Container Registry integrate with their clouds' IAM and are the natural choice for workloads running there.
Starting a container means choosing its image, ports, volumes, environment, network, restart policy and resource limits. One-off runs use docker run; multi-container setups are described declaratively in a Compose file.
Creates and starts a container. Common flags: -d detached, -p 8080:80 publish a port, -e env vars, -v mounts, --name, --rm to clean up on exit and -it for an interactive shell.
A compose.yaml file declares services, networks and volumes; docker compose up -d starts the whole stack and down removes it. Services reach each other by service name, and depends_on with health checks controls start order.
Restart policies (--restart unless-stopped), memory and CPU limits, health checks, env files, log drivers and --read-only roots are all set at run time, so one image can be tuned per environment.
You build images from a Dockerfile with docker build -t name:tag ., which BuildKit executes step by step and caches. Good images are small, rebuild quickly when code changes, and contain only what the app needs at run time.
A text recipe: FROM a base, WORKDIR, COPY files, RUN commands, ENV, EXPOSE, USER and finally CMD or ENTRYPOINT. Use the exec (JSON array) form for CMD so signals reach your process, and keep a .dockerignore.
A changed instruction invalidates its layer and every one after it. Copy dependency manifests and install them before copying source, and use cache mounts (RUN --mount=type=cache) for package manager caches.
Multi-stage builds compile in a full toolchain image then copy only the output into a slim, Alpine or distroless runtime. Fewer packages means a smaller download and fewer CVEs; never bake secrets into layers, use build secrets instead.
Containers are a weaker boundary than VMs because they share the kernel. Security comes from trustworthy, minimal, scanned images plus a locked-down runtime: non-root users, dropped capabilities and no access to the Docker socket.
Run as non-root, add --cap-drop ALL and only the capabilities you need, use --read-only and --security-opt no-new-privileges, avoid --privileged, and never mount /var/run/docker.sock into untrusted containers. Rootless mode limits the blast radius further.
Start from official or verified bases, pin versions, rebuild regularly to pick up patches, and scan for known CVEs with Docker Scout, Trivy or Grype in CI. Signing and SBOMs let consumers check what they run.
The docker command talks to the daemon's API and is grouped by object: docker image, docker container, docker volume, docker network. docker inspect dumps any object as JSON and docker system prune reclaims disk space.
docker image ls, pull, push, tag, rm and prune manage local images; docker image history shows each layer and its size, handy for finding what bloats an image.
docker ps -a, logs -f, exec -it, stop, start, rm and stats cover the container life cycle; docker cp moves files in and out and docker inspect shows mounts, IPs and the effective config.
docker volume create, ls, inspect, rm and prune. Removing a container does not remove its named volumes, so prune deliberately; back a volume up by mounting it into a throwaway container that runs tar.
docker network create, ls, connect, disconnect and inspect. Attach containers to a user-defined network so they can find each other by name through Docker's embedded DNS.
By default containers join a bridge network with private IPs and reach the outside through NAT; -p host:container publishes a port. User-defined bridges add name-based discovery, host mode shares the host stack, and overlay networks span Swarm nodes. Published ports bypass some host firewall rules, a common surprise on Linux.
Containers should make development smoother, not slower. Use Compose for the whole local stack, mount or sync code for fast feedback, run the same images in tests and CI, and attach a debugger to the running process.
Bind-mount the source and run the framework's dev server inside the container, or use docker compose watch to sync changed files and rebuild when dependency files change. File-watching over Desktop mounts may need polling.
Expose the runtime's debug port (for example Node's --inspect=0.0.0.0:9229) and attach from your editor, or use dev containers. docker debug opens a toolbox shell in slim containers that have no shell of their own.
Run tests against real dependencies in containers instead of mocks. Testcontainers starts throwaway databases and brokers from test code; alternatively a Compose file can stand up the stack for integration tests.
CI builds the image once, tests it, scans it and pushes it with an immutable tag. Use BuildKit cache export (for example the GitHub Actions cache backend) so pipeline builds stay fast.
In production something must schedule containers, restart failures, roll out new versions and route traffic. Choose between a managed platform that just runs your image, a full orchestrator like Kubernetes, or something lighter.
Services like Google Cloud Run, AWS App Runner, Azure Container Apps and Fly.io take an image and handle scaling, TLS and routing. The least operational work, at the cost of platform limits and lock-in.
The industry-standard orchestrator: Deployments, Services, Ingress and ConfigMaps describe desired state, and controllers converge to it. Powerful and portable across clouds, but a lot to learn and operate; managed offerings (EKS, GKE, AKS) remove the control-plane work.
HashiCorp's scheduler: a single binary that runs containers alongside plain executables and VMs. Simpler than Kubernetes and pairs with Consul and Vault.
Orchestration built into Docker Engine: docker swarm init, then deploy Compose-format stacks with docker stack deploy. Easy for small clusters, but its ecosystem is far smaller than Kubernetes'.