Skip to content

Docker Compose

Running a real application almost always means running more than one container — a web server, a database, maybe a cache. Without Compose you would open multiple terminals, type a long docker run command for each service, and remember to wire them together manually on the same network. That process is fragile and impossible to share reliably.

Docker Compose lets you describe your entire multi-container application in a single file called compose.yaml. One command starts everything:

Terminal window
docker compose up

One command tears it all down:

Terminal window
docker compose down

Compare running a simple web app two ways.

Without Compose:

Terminal window
docker network create myapp-net
docker run -d \
--name web \
--network myapp-net \
-p 8080:8080 \
-e APP_ENV=production \
myapp:latest

With Compose:

services:
web:
image: myapp:latest
ports:
- "8080:8080"
environment:
- APP_ENV=production

The Compose version is self-documenting, version-controlled, and reproduced identically by anyone on your team.

This module walks you through every layer of Docker Compose:

LessonTopic
1 (this page)Why Compose — one-file declarative apps
2compose.yaml structure in depth
3Multi-service apps with networking
4Environment variables, volumes, and networks
5Lifecycle commands and scaling

Here is the smallest useful compose.yaml — a single Nginx service:

services:
web:
image: nginx:alpine
ports:
- "8080:80"

Start it with docker compose up (add -d to run in the background). Visit http://localhost:8080 and you see the Nginx welcome page. Stop it with Ctrl-C, or docker compose down if you used -d.

The snippet below writes a compose.yaml, starts it, and checks the running service — all inside Play with Docker.

# Write a minimal compose.yaml
cat > compose.yaml <<'EOF'
services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
EOF

# Start in detached mode
docker compose up -d

# Check running services
docker compose ps

# Fetch the Nginx welcome page
curl -s http://localhost:8080 | head -5

# Tear it down
docker compose down
What is the main benefit of using Docker Compose over plain docker run commands?
Which command starts all services defined in compose.yaml in the foreground?
Which command is correct for Compose v2?
What is the standard filename for a Compose configuration?