LESSON · 1 OF 6

Why Docker Compose

Why Docker Compose

By now a single docker run for a real service is a mouthful - a name, a port, a few environment variables, a volume, a network, a restart policy:

bash
docker run -d --name db \
  --network appnet \
  -e POSTGRES_PASSWORD=s3cret \
  -e POSTGRES_DB=orders \
  -v pgdata:/var/lib/postgresql/data \
  --restart unless-stopped \
  postgres:16-alpine

That is one service. A real app has several - a web server, a database, a cache - each with its own long command, plus a network to create first. Typing all that by hand, in the right order, every time, is error-prone and impossible to hand to a teammate cleanly.

The problem Compose solves

Two pain points come from managing multi-container apps by hand:

  • The commands are long and easy to get wrong, and they live only in your shell history or a fragile script.
  • Nothing captures how the pieces fit together. A new teammate has no single file that says "this app is these three services, wired up like this".

What Compose is

Docker Compose lets you describe your whole application in one file - every service, its image, ports, environment, volumes, and networks - and then start all of it with a single command. The file is the source of truth. Commit it to the repo and anyone can bring the app up identically.

bash
docker compose up

That one command reads the file and starts every service, creating the networks and volumes they need along the way. No long flags, no remembering the order.

Compose is built in

Compose ships with Docker as the docker compose subcommand - nothing extra to install here. The rest of this topic covers the file format and the handful of commands you use to run it.

Spin up a fresh environment and practice live.
docker · fresh machine · ready in under a minute