Docker for Deployment
Just enough Docker to ship — no Kubernetes nonsense.
Why Docker at all
Docker solves one problem at deploy time: the thing that runs on your laptop is the same thing that runs on the server, bit for bit. No "works on my machine", no Node version mismatch, no missing system library. You trade a week of learning curve for never hand-debugging a deployment environment again.
Images vs containers
An image is a read-only snapshot of a filesystem plus a default command. A container is a running instance of that image with a writable layer on top. You build images from a Dockerfile, you run containers from images, and you throw containers away constantly — they are cattle, not pets. Data that needs to survive lives in volumes, which we get to next.
Volumes are where your data lives
Anything written inside a container disappears when the container is removed. To persist data you mount a volume:
services:
db:
image: postgres:16
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
The first time I deployed Postgres I forgot the volume line and lost a week of data on my first redeploy. Do not be me. Named volumes (pgdata) are managed by Docker. Bind mounts (./data:/var/lib/postgresql/data) are managed by you and are easier to back up with rsync.
Networks let containers find each other
Compose puts every service in a shared network and lets them reach each other by service name. Your app connects to Postgres at postgres://db:5432 — not localhost. The db hostname only resolves inside the network, which is exactly what you want: your database is never exposed to the public internet unless you explicitly publish its port.
docker compose up is your deploy command
For a single-box deployment, docker compose up -d is the entire deploy step. Write a compose.yml that declares your app, your database, your reverse proxy, and their volumes. Commit it to the repo. On the server, git pull && docker compose up -d --build. That is it. You do not need Kubernetes, Nomad, or Docker Swarm for this — and everyone you meet who insists you do has never shipped a side project.
Key takeaways
- Images are snapshots; containers are disposable instances
- Volumes persist data — forget one and you lose everything on redeploy
- Compose services reach each other by name on a private network
- `docker compose up -d` is the entire deploy command for most apps