The Production Docker Compose Cheat Sheet: Services, Volumes, Networks & Healthchecks
Quick reference for multi-container orchestration: restart policies, healthcheck probes, isolated bridge networks, and environment variables.
Essential Docker Compose CLI Commands
Daily management commands for starting, inspecting, and stopping stacks.
| Command Syntax | Action | Description |
|---|---|---|
| `docker compose up -d` | Detached Startup | Builds, creates, and launches containers in the background. |
| `docker compose down -v` | Tear Down with Volumes | Stops containers, networks, and permanently purges named volumes. |
| `docker compose logs -f --tail=100 web` | Stream Logs | Follows real-time stdout/stderr log output for specific service. |
| `docker compose exec -it db psql -U user` | Execute Shell | Runs an interactive shell or database CLI inside running container. |
Production Service Architecture Block
Standard multi-container configuration with database healthcheck and restart policies.
version: "3.8"
services:
web:
build:
context: .
dockerfile: Dockerfile
restart: always
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- DATABASE_URL=postgres://app:secret@db:5432/appdb
depends_on:
db:
condition: service_healthy
networks:
- internal-net
db:
image: postgres:16-alpine
restart: always
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: secret
POSTGRES_DB: appdb
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app -d appdb"]
interval: 5s
timeout: 5s
retries: 5
networks:
- internal-net
volumes:
db_data:
networks:
internal-net:
driver: bridgeInteractive Client-Side Tools for this Guide
Test and run these patterns directly inside your browser with zero server uploads:
cURL to Fetch, Axios & Python Code Converter
Paste raw cURL commands from browser DevTools and instantly convert them into clean JavaScript, Python, or Go code snippets.
JSON Formatter & Validator (Beautify & Minify)
Clean up messy API responses, fix syntax glitches, and compress JSON payloads directly in your browser.
Base64 Encoder & Decoder (Text & Images)
Convert binary images and strings into Base64 format for web embeds, CSS inlining, and data transmission.
Frequently Asked Questions
What is the difference between docker-compose (v1) and docker compose (v2)?
Docker Compose v2 is integrated natively into the official Docker CLI written in Go, replacing the deprecated standalone Python script `docker-compose`.
How do you handle zero-downtime container deployments?
Combine `docker compose up -d --no-deps --build <service>` with a reverse proxy like Nginx or Traefik that performs healthcheck routing.