Emergency CheatsheetCODE: 019-DOCKER-COMPOSE-OPS⏱️ ~8 min read

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

Full Poster Preview

Size: 1080×1350 (4:5)Enlarge or download for reference

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. Run docker compose start to 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 -v flag 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 showing Restarting indicates an entrypoint or configuration crash.
  • logs -f <service>: Tails the real-time logs of a specific service. Append --tail 100 to prevent console flooding and -t for 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. Use sh instead of bash because 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 with up -d to recreate updated services with zero unnecessary downtime.
  • up -d --build: Triggers a fresh build for services containing a build: 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 use up -d to 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 -a deletes 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 with ss -ltnp and adjust host port bindings in ports:.
  • App crashes on boot because DB is not ready: Basic depends_on only controls startup order, not operational readiness. Configure a healthcheck on the database service and declare condition: service_healthy on dependent apps.
  • YAML updates have no effect: You ran restart instead of up -d. Re-run docker compose up -d to 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 using docker compose up -d --remove-orphans.

Emergency Incident Checklist

  1. docker compose ps — Pinpoint crashing or restarting containers.
  2. docker compose logs --tail 100 <service> — Identify the root cause stack trace.
  3. docker compose config — Verify that secrets and environment variables resolved accurately.
  4. docker compose exec <service> sh — Test network DNS resolution to adjacent services.
  5. After updating configurations, always apply with docker compose up -d.
  6. Never run down -v in 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.