Skip to content
Guest
Learn Docker · Course Syllabus Show lessons
Networking & Persistence · 8 min read · Intermediate

Docker Compose & Multi-Container Stacks

Define and launch multi-service apps (web + API + database) with a single compose.yaml and docker compose up.

What you'll learn

  • Define services, ports, environment variables, and volumes in compose.yaml
  • Connect containers by service name using Compose's automatic DNS network
  • Start and tear down an entire stack with docker compose up -d and down

Docker Compose lets you describe your entire multi-container architecture (frontend, backend API, PostgreSQL, Redis) in one declarative compose.yaml file. Services on the same Compose network automatically resolve each other by service name (e.g., DATABASE_URL=postgres://user:pass@db:5432/app).

Fill-in-the-Blank Exercise

Launch Compose Stack

Build and start all services in detached mode with Docker Compose.

docker  up -d --

Live Compose YAML Lab

Bashcompose_check.sh
Expected OutputClick “Run Live” to compile with GNU Bash
services:
api:
  build: .
  ports: ["8787:8787"]
  depends_on: [db]
db:
  image: postgres:16-alpine
  volumes: ["pgdata:/var/lib/postgresql/data"]
volumes:
pgdata:

Check Your Understanding

Score: 0 / 1

1. Inside a Docker Compose stack with services 'api' and 'db', what hostname should 'api' use to connect to PostgreSQL?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind