Skip to content
Latchkey

Docker Compose Cheat Sheet: Commands & compose.yaml Keys

The docker compose commands and compose.yaml keys in one reference.

Lifecycle commands and the service definition keys for multi-container apps.

Commands

CommandDoes
docker compose up -dStart in background
docker compose up --buildRebuild then start
docker compose down -vStop + remove volumes
docker compose psList services
docker compose logs -f svcFollow a service log
docker compose exec svc shShell into a service
docker compose run --rm svc cmdOne-off command

Service keys

KeyPurpose
image / buildPull image or build from context
portshost:container port maps
environment / env_fileEnv vars
volumesBind/named mounts
depends_onStart order (+ condition)
healthcheckLiveness probe
networksAttach to networks
restartno / on-failure / always

Example

compose.yaml
services:
  api:
    build: .
    ports: ["8080:8080"]
    env_file: .env
    depends_on:
      db: { condition: service_healthy }
  db:
    image: postgres:16
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER}"]
      interval: 5s

Key takeaways

  • depends_on with condition: service_healthy waits for readiness, not just start.
  • down -v also drops named volumes - omit -v to keep data.
  • run --rm is ideal for one-off tasks like migrations.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →