Hands-on guide series
Docker in Production: A Hands-On Guide
A seven-part, hands-on guide to running Docker in production on a single VPS: your first container and the image model, a Dockerfile and a multi-stage build, a Compose stack with a datastore, volumes and networks, resource limits and restart policies, logging and observability, and security hardening. Every command tested on a live Ubuntu 24.04 server.
What you will build
Security is layers, not a switch. Each part closes a different category of attack, from the automated sweep that finds a brand-new server, to the day one gets in anyway. Read them in order, or jump to what you need.
- 1
The Docker Engine and Your First ContainerInstall the Docker engine on a bare Ubuntu 24.04 slice, run your first Docker container in one command, then meet the image and container split that runs it.10 min - 2
Images and Dockerfiles: Build a Small App ImageBuild a Docker image from a Dockerfile on Ubuntu 24.04, read its layers with docker history, then shrink it from 477 MB to under 20 MB with multi-stage.6 min - 3
Compose a Multi-Service AppUse Docker Compose to run an app and a Redis datastore as one stack: one file, a private network, health checks, and both services up and reachable.7 min - 4
Volumes and Networks That Persist and ConnectProve Docker volumes keep data across a full teardown, and that a user-defined network lets containers resolve each other by name where the bridge cannot.6 min - 5
Resource Limits and Restart PoliciesSet Docker resource limits for memory and CPU, watch docker stats enforce them, and add a restart policy that recovers a container after it crashes.6 min - 6
Logging and ObservabilityRead docker logs from a running stack, cap them with json-file rotation so they cannot fill the disk, and use docker stats and inspect to see inside.6 min - 7
Security and HardeningHarden Docker security for a container: run as non-root, use a read-only filesystem, drop capabilities, and keep the secret out of the image.6 min