Production Docker Compose: Multi-service Healthchecks, Secrets & Clean Updates
Manage multi-container stacks safely: service dependency ordering, env var protection, zero-downtime container updates, and prune jobs.
Authored by: Vibe DevOps · Published: 10/23/2026
Most small and mid-sized web stacks don't start with Kubernetes; they start with a clean compose.yaml: a web application, a database, perhaps a Redis cache or a queue worker. Docker Compose enables you to define and manage an entire production stack using intuitive commands. However, because commands look similar, critical mistakes happen frequently: confusing stop with down, wondering why restart ignores YAML changes, or accidentally wiping databases with down -v. This comprehensive runbook walks through the 6 core command groups featured on our emergency cheatsheet, detailing the underlying mechanics and operational best practices.
Verification Scope: Commands documented in this guide follow modern Docker Compose v2 syntax (docker compose as a Docker CLI plugin). The legacy docker-compose v1 (hyphenated) has reached end-of-life and is deprecated. Always adapt service names, mount paths, and project names to match your production repository.
Core Architecture: Project, Service & Container
Docker Compose organizes resources around the concept of a Project. By default, the project name is inferred from the working directory name (customizable via -p or COMPOSE_PROJECT_NAME). Each Service defined in the YAML file instantiates one or more isolated Containers. Compose automatically provisions a default bridge network for the project, allowing containers to communicate using predictable service names (e.g. web connecting to db:5432).
1. Starting & Stopping the Stack
docker compose up -d
docker compose stop
docker compose down
up -d: Creates missing networks, volumes, and containers, running them in the background (detached mode). If configurations haven't changed, existing containers remain untouched; if configurations or images changed, Compose recreates only the affected containers.stop: Gracefully terminates container processes without removing anything. Networks and volumes remain intact. Rundocker compose startto resume them immediately.down: Stops and removes the containers and the default project network. Named data volumes are preserved, keeping database persistence safe unless the-vflag is explicitly supplied.
2. Service Status & Log Triage
docker compose ps
docker compose logs -f <service>
docker compose top
ps: Lists running containers, published ports, and healthcheck status. A container repeatedly showingRestartingindicates an entrypoint or configuration crash.logs -f <service>: Tails the real-time logs of a specific service. Append--tail 100to prevent console flooding and-tfor RFC3339 timestamps. Omitting the service name aggregates logs across all stack components.top: Displays live operating system processes running inside each container, useful for diagnosing CPU hogs or zombie background tasks.
3. Container Access & Inspection
docker compose exec <service> sh
docker compose run --rm <service> <command>
docker compose cp <service>:<path> .
exec: Opens an interactive shell inside an already running container. Useshinstead ofbashbecause minimal Alpine-based images rarely bundle bash.run --rm: Launches a new one-off container from the service definition to execute administrative tasks (like DB migrations), and removes it upon exit without conflicting with published ports.cp: Bidirectionally copies files between containers and the host system, invaluable for extracting crash dumps or runtime configuration files.
4. Updates & Rebuilding
docker compose pull
docker compose up -d --build
docker compose restart <service>
pull: Downloads updated image layers from the container registry without modifying running instances. Follow withup -dto recreate updated services with zero unnecessary downtime.up -d --build: Triggers a fresh build for services containing abuild:definition and gracefully updates services with code changes.restart: Restarts container processes in-place. It DOES NOT re-read changes from compose.yaml or .env files. Always useup -dto apply configuration changes.
5. Configuration Verification
docker compose config
docker compose config -q
docker compose ls
config: Validates and renders the final resolved YAML after variable substitution and file inheritance. This is the primary command for debugging environment variable resolution.config -q: Quiet syntax check. Prints nothing on success and returns a non-zero exit code on syntax errors, making it ideal for CI/CD pre-flight checks.ls: Lists all Compose projects currently registered and running across the host.
6. Safe Cleanup & Maintenance
docker compose down -v
docker image prune
docker system df
down -v: Stops containers and permanently deletes all volumes declared in the file. Any data stored in named volumes will be lost. Use exclusively in local development or after verifying automated backups.image prune: Safely removes dangling images left behind by iterative image builds. Adding-adeletes all unused images across the Docker daemon.system df: Summarizes total disk usage across containers, images, volumes, and build cache.
Common Pitfalls & Solutions
port is already allocated: Another host process or Compose stack has bound the port. Verify withss -ltnpand adjust host port bindings inports:.- App crashes on boot because DB is not ready: Basic
depends_ononly controls startup order, not operational readiness. Configure ahealthcheckon the database service and declarecondition: service_healthyon dependent apps. - YAML updates have no effect: You ran
restartinstead ofup -d. Re-rundocker compose up -dto allow Compose to diff the state and replace the container. Found orphan containers: A service was renamed or removed from the compose file. Clean up stray containers usingdocker compose up -d --remove-orphans.
Emergency Incident Checklist
docker compose ps— Pinpoint crashing or restarting containers.docker compose logs --tail 100 <service>— Identify the root cause stack trace.docker compose config— Verify that secrets and environment variables resolved accurately.docker compose exec <service> sh— Test network DNS resolution to adjacent services.- After updating configurations, always apply with
docker compose up -d. - Never run
down -vin production unless verified snapshot backups exist.
💡 Team Storage & Usage Tips
Store the vector PDF in your internal team repository (Notion, Confluence) or print it out in A4 format next to your workstation for rapid troubleshooting during midnight production outages.