Home › Docker Tutorial › Docker Compose
Docker Compose
Run several containers from one file.
Real apps need several containers (web, database, cache). Docker Compose describes them all in one compose.yaml file and starts them together with docker compose up. depends_on sets the start order, and compose creates a shared network so services reach each other by service name (for example host db).
Example code
services:
web:
image: nginx:1.27
ports:
- "8080:80"
depends_on:
- db
db:
image: postgres:17
environment:
POSTGRES_PASSWORD: example
volumes:
- dbdata:/var/lib/postgresql/data
volumes:
dbdata: