Pcornel
Browse topics
Options
Recent
Favorites
Containers · Technical reference

Docker Compose Basics

Direct answer

Docker Compose defines services, networks and volumes in compose.yaml and runs them together with docker compose.

When to use this

Use it to run multi-container applications on a single host.

First 30 seconds

1. docker compose config — valid?

2. docker compose up -d.

3. docker compose ps and logs.

4. Healthchecks passing?

5. Persist data in named volumes.

Operational verification

compose.yaml → network + volumes → services

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Docker / containerd / Podman / Kubernetes / OCI-compatible platforms
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformDocker / containerd / Podman / Kubernetes / OCI-compatible platforms
Scope / prerequisiteUse it to run multi-container applications on a single host.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 How to verify Verify boundary

Validate with docker compose config before deploying. After up -d, confirm every service is running and healthy. Test that services reach each other by service name.

Step 2 Common failures Narrow the fault

depends_on without a health condition only orders startup; it does not wait for readiness. Running compose from another directory creates a second project with the same services. Secrets placed directly in environment entries end up in docker inspect output.

Key points

Services resolve each other by name. Use .env for variables and depends_on with healthchecks. docker compose config shows the merged result.

Key checks
  • docker compose config — merged configuration
  • docker ps -a — containers and exit codes
  • docker logs <c> — container output
  • docker inspect <c> — config, mounts, network, state
ReferenceWhat it is1 section · depth on demand

How it works

Compose names resources with the project name (directory name by default). It creates networks and volumes first, then containers in dependency order. depends_on with condition: service_healthy waits for a healthcheck to pass.

ReferenceImportant terms & boundaries2 sections · depth on demand

In depth

Compose turns one YAML file into a named project: networks, volumes and containers labelled with the project name, by default the directory name.

Startup order vs readiness

services:
  db:
    image: postgres:17
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app"]
      interval: 5s
      retries: 10
  api:
    image: myapi:1.4
    depends_on:
      db: { condition: service_healthy }

Plain depends_on: [db] only starts db first; condition: service_healthy waits for its health check to pass.

Configuration layering

MechanismUse
.env in the project directoryVariable values for ${VAR} interpolation
env_file:Environment variables passed into a container
compose.override.yamlApplied automatically on top of compose.yaml (local dev changes)
-f a.yaml -f b.yamlExplicit layering, later files win
profiles:Optional services started only with --profile

docker compose config prints the fully merged and interpolated result; check it before deploying.

Worked update of one service

docker compose pull api
docker compose up -d --no-deps api      # recreate only api
docker compose ps
docker compose logs -f --tail=50 api

up -d only recreates containers whose configuration or image changed; volumes are kept unless down -v is used.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • Secrets in the compose file.
ReferenceConfiguration & state1 section · depth on demand

Compose example and commands

services:
  web:
    image: nginx:1.27
    ports: ["8080:80"]
    depends_on: { api: { condition: service_healthy } }
  api:
    image: myapi:1.4
    environment: [DB_HOST=db]
    healthcheck: { test: ["CMD", "curl", "-f", "http://localhost:8000/health"], interval: 10s }
  db:
    image: postgres:17
    volumes: [pgdata:/var/lib/postgresql/data]
volumes: { pgdata: {} }

docker compose up -d, docker compose ps, docker compose logs -f api, docker compose down (add -v only to delete volumes). Documented example, not captured output.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
docker compose basicsdocker compose upcompose.yaml
Confirmation

Confirm action

Continue?