Docker Compose Dev, Debugging, CI, and Production Patterns

Developer workflows, troubleshooting commands, CI flows, and small-host production Compose patterns.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Developer Workflows

Common patterns for local development, tests, and one-off tasks.

Watch files and sync/rebuild

Watches project files and applies sync or rebuild actions when configured.

bashANYdockercomposewatch
bash
docker compose watch

Useful for tighter inner-loop development.

Run test suite in service

Runs tests in a disposable service container.

bashANYdockercomposetests
bash
docker compose run --rm app pytest -q

Great for reproducible local and CI test runs.

Install dependencies in app service

Executes dependency installation in the service environment.

bashANYdockercomposerun
bash
docker compose run --rm app npm install

Useful when the project expects toolchains inside the container.

Scale a service

Starts multiple instances of a service.

bashANYdockercomposescale
bash
docker compose up -d --scale worker=3

Useful for queue consumers and basic horizontal scaling tests.

Run database migration

Runs a migration task in an ephemeral application container.

bashANYdockercomposemigrations
bash
docker compose run --rm web python manage.py migrate

Common during deploy or local setup.

Debugging and Troubleshooting

Common inspection and diagnosis commands.

Validate effective config

Checks whether the Compose config is valid without printing it.

bashANYdockercomposevalidate
bash
docker compose config --quiet

Useful in pre-commit or CI validation steps.

List all containers including stopped

Shows current and exited containers for the project.

bashANYdockercomposepsdebug
bash
docker compose ps -a

Helpful for identifying crash loops and one-off exits.

View recent logs since time

Shows recent logs for a specific service.

bashANYdockercomposelogssince
bash
docker compose logs --since=10m api

Good for focused debugging during incident response.

Inspect runtime env

Prints environment variables inside the running service.

bashANYdockercomposeexecenv
bash
docker compose exec api env | sort

Useful when debugging interpolation and config loading issues.

Start ephemeral debug shell

Launches a temporary debug shell using the service image.

bashANYdockercomposedebugshell
bash
docker compose run --rm --entrypoint sh api

Useful when startup scripts or commands are failing.

Print container mounts and settings

Inspects the underlying container created for a service.

bashANYdockercomposeinspect
bash
docker inspect $(docker compose ps -q api)

Helpful when you need low-level Docker details not shown by Compose.

CI/CD and Release Patterns

Compose commands for automation pipelines.

Build stack in CI

Builds the project with CI-specific overrides applied.

bashANYdockercomposecibuild
bash
docker compose -f compose.yaml -f compose.ci.yaml build

Useful for test tools, fake services, and cache controls.

Run integration stack and exit with service code

Runs an integration stack and returns the test container exit code.

bashANYdockercomposecitests
bash
docker compose up --abort-on-container-exit --exit-code-from test

A common pattern for integration test pipelines.

Tear down CI stack with volumes

Fully cleans up the test environment and removes stale containers.

bashANYdockercomposecicleanup
bash
docker compose down -v --remove-orphans

Good hygiene for repeatable automation.

Pull latest images and recreate

Refreshes image-based services to the newest available tags.

bashANYdockercomposedeploy
bash
docker compose pull && docker compose up -d

Simple deployment flow for smaller self-hosted stacks.

Production-Minded Compose Patterns

Common patterns for small-host or self-hosted deployments.

App with healthcheck and restart policy

Adds self-healing and health visibility to a service.

yamlANYdockercomposehealthcheckrestart
yaml
services:
  app:
    image: myapp:${APP_TAG:-latest}
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://localhost:3000/health || exit 1"]
      interval: 30s
      timeout: 5s
      retries: 3

Useful for small-host production deployments and uptime monitoring.

Proxy + app pattern

Basic reverse-proxy plus app service pattern.

yamlANYdockercomposereverse-proxy
yaml
services:
  proxy:
    image: nginx:alpine
    ports:
      - "80:80"
    depends_on:
      app:
        condition: service_started
  app:
    image: myapp:${APP_TAG:-latest}

Common for simple deployments on a single VM.

Backup sidecar pattern

Defines an operational backup task as a profile-gated service.

yamlANYdockercomposebackupops
yaml
services:
  db:
    image: postgres:16
    volumes:
      - pgdata:/var/lib/postgresql/data
  backup:
    image: postgres:16
    profiles: ["ops"]
    depends_on:
      - db
    entrypoint: ["sh", "-c", "pg_dump -h db -U postgres appdb > /backup/appdb.sql"]
    volumes:
      - ./backup:/backup

volumes:
  pgdata: {}

Keeps maintenance commands versioned alongside the stack.

Recommended next

No recommendations yet.