What is Docker Compose?
Docker Compose defines and runs multi-container applications from a single YAML file with one command.
Real applications are made of several containers — a web server, an API, a database, a cache. Running and wiring them up by hand is tedious. Docker Compose solves this by describing your whole stack in one file.
How it works
You write a compose.yml file listing each container as a service. Then docker compose up starts everything at once, creating the networks and volumes automatically.
Why it is great
- The entire environment is version-controlled in one file.
- New teammates run one command to start everything.
- Services get a shared network and can reach each other by name.
Example
# Start the whole stack in the background
docker compose up -d
# See running services
docker compose ps
# Stop and remove everything
docker compose downWhen to use it
- A developer replaces three separate docker run commands with a single docker compose up to start a web app, database, and cache together.
- A team commits a compose.yml to the repo so any new developer can reproduce the full local environment with one command.
- A QA engineer uses docker compose up to spin up an isolated copy of the entire application stack for each test suite run.
More examples
Start all services
Starts every service defined in compose.yml in the background and then lists their status.
# Start all services in detached mode
docker compose up -d
# View running services
docker compose psStop and remove all services
Tears down the whole stack; -v also deletes named volumes declared in the compose file.
# Stop and remove containers, networks
docker compose down
# Also remove volumes
docker compose down -vView logs across all services
Streams interleaved log output from all services, colour-coded by service name.
# Follow logs from all services
docker compose logs -f
# Logs from a single service only
docker compose logs -f api
Discussion