CoursesDocker for beginnersData, networking & Compose

Multi-container apps with Compose

One file, a whole stack.

Beginner12 min · lesson 14 of 16
In plain terms
Compose is the cast-and-setup list for a stage play, written in one script: who’s on stage, what props they need, how they’re wired together. “compose up” raises the curtain on the entire production at once, instead of walking each actor out by hand.
THE COMPOSE STACK (ONE FILE)
web service
build: .
image from the local Dockerfile
ports 8080:3000
published to the host
db service
image: postgres:16
not published, internal only
volume pgdata
persists the database
Compose wiring
private network
auto-created for the stack
DNS by service name
web connects to "db"
One docker compose up creates the network and volume and starts both services; web reaches db by name.

Real applications are rarely one container — a web app needs a database, maybe a cache, maybe a worker. Starting each by hand with the right flags, in the right order, on the right network gets tedious and error-prone fast. Docker Compose replaces all of that with a single YAML file that describes every service, and one command to bring the whole stack up or down.

compose.yaml
services:
web:
build: . # build from the Dockerfile here
ports: ["8080:3000"] # publish to the host
environment:
DATABASE_URL: postgres://db:5432/payments # reach "db" by name
depends_on: [db]
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: devsecret
volumes: ["pgdata:/var/lib/postgresql/data"]
volumes:
pgdata:

One command brings it all up

docker compose up reads the file, creates a private network for the stack, creates the named volumes, and starts every service — and because they share a Compose network, they resolve each other by service name (web connects to db as “db”). docker compose down tears it all back down. The whole environment becomes reproducible and versioned in one file you can commit.

terminal
$ docker compose up -d # build/create/start the whole stack
$ docker compose ps # what is running
$ docker compose logs -f web
$ docker compose down # stop and remove containers + network
Compose is single-host
Compose runs your whole stack on one machine, which is perfect for local development and small deployments. It does not spread containers across multiple servers, restart them on another host when one dies, or scale them out — that is the job of orchestration (Swarm or Kubernetes), which the next lesson points you toward.