The Compose file keys you actually use: services, build, ports, environment, volumes, networks, depends_on with healthchecks, restart policies and profiles.
A typical API + database + cache stack. The file is usually named compose.yaml or docker-compose.yml; the top-level version: key is obsolete.
| Key | Meaning |
|---|---|
image / build | Use an existing image, or build one (both = build and tag it) |
ports | Publish to the host; omit for internal-only services |
expose | Document internal ports only |
environment / env_file | Env vars; ${VAR} is substituted from .env or the shell |
volumes | Named volumes or ./relative bind mounts |
depends_on | Start order; add condition: service_healthy to wait for readiness |
restart | no, always, on-failure, unless-stopped |
command / entrypoint | Override the image CMD / ENTRYPOINT |
profiles | Optional services, enabled with --profile |
networks | Custom networks (a default one is created per project) |
Keep a base compose.yaml plus a compose.override.yaml for local development (bind mounts, debug ports); Compose merges the override automatically. Check the final result with docker compose config.