# Docker Compose for Multi-Container Apps

> Describe an app and its dependencies in one YAML file for reproducible local development, testing and small deployments. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/devops/docker-compose
Last updated: 2026-11-28

Describe an app and its dependencies in one YAML file for reproducible local development, testing and small deployments.

Beginner · about 4 hours · difficulty 2/5

Learn first: [Building Good Images](https://www.internhack.in/roadmaps/tracks/devops/dockerfiles-images)

**Docker Compose** defines multiple services, networks and volumes in a `compose.yaml` file and starts them together with `docker compose up`. It is the standard way to give every developer the same local stack and to run integration tests in CI.

### What to learn

- `services` with `image` or `build`, `ports`, `environment`/`env_file`, `volumes`, `depends_on`.
- **Health checks** plus `depends_on: condition: service_healthy` so the app waits for the database to be ready, not just started.
- Named volumes for data and bind mounts for live code reload.
- **Profiles** to start optional services, and override files (`compose.override.yaml`) for per-environment tweaks.
- Commands: `up -d`, `down -v`, `logs -f`, `exec`, `ps`, `build`, `config` to see the merged result.

### Where it fits

Local development, CI integration tests, demos, and small single-host deployments. For multi-host scheduling, self-healing and rolling updates you need an orchestrator such as Kubernetes.

### Pitfalls

Committing real secrets in `environment`, relying on startup order without health checks, and `down -v` wiping a database you wanted to keep.

**Good enough to move on:** a new teammate can clone your repo and have the full stack running with one command.

## Key concepts

- **services, networks, volumes**
- **Environment and env files**
- **Health checks and depends_on**
- **Override files and profiles**
- **Compose in CI**
- **Compose Watch for dev**

## Mini project

Write a compose.yaml for an app, Postgres, Redis and an Nginx proxy with health-checked startup, then use it in a CI job that runs integration tests against the stack.

## Check yourself

Why is depends_on alone not enough to guarantee your app can connect to the database on startup?

## Free resources

- [Docker Compose overview](https://docs.docker.com/compose/) (Docker)
- [Compose file reference](https://docs.docker.com/reference/compose-file/) (Docker)

Previous: [Container Registries](https://www.internhack.in/roadmaps/tracks/devops/container-registries) · Next: [Container Security Essentials](https://www.internhack.in/roadmaps/tracks/devops/container-security)

## More in Containers in Depth

- [Containers and Docker Basics](https://www.internhack.in/roadmaps/tracks/devops/container-fundamentals)
- [Building Good Images](https://www.internhack.in/roadmaps/tracks/devops/dockerfiles-images)
- [Container Registries](https://www.internhack.in/roadmaps/tracks/devops/container-registries)
- [Docker Compose for Multi-Container Apps](https://www.internhack.in/roadmaps/tracks/devops/docker-compose)
- [Container Security Essentials](https://www.internhack.in/roadmaps/tracks/devops/container-security)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [DevOps Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/devops)
