Multi-container apps with Compose
One file, a whole stack.
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.
services:web:build: . # build from the Dockerfile hereports: ["8080:3000"] # publish to the hostenvironment:DATABASE_URL: postgres://db:5432/payments # reach "db" by namedepends_on: [db]db:image: postgres:16environment:POSTGRES_PASSWORD: devsecretvolumes: ["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.
$ 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