One File, Whole Stack
From Flag Soup to Declaration
Scenario: Deploying the stack takes four hand-typed docker run commands with eleven flags each. Every deploy, someone forgets one - wrong port, missing volume, no restart policy. The fix isn't discipline; it's declaring the stack in a file that IS the documentation.
Docker Compose is a tool for exactly this: instead of typing a long docker run command per container, you describe your whole multi-container app - each service (Compose's word for one container plus its settings), its image, ports, volumes, and how services depend on each other - in a single YAML file (a human-readable, indentation-based text format for structured data, much like JSON but easier to hand-write), and Compose brings the whole thing up or down as one unit:
# docker-compose.yml
services:
web:
image: nginx:alpine
ports:
- "8088:80"
volumes:
- ./html:/usr/share/nginx/html:ro
restart: unless-stopped
depends_on:
- cache
cache:
image: redis:7-alpine
volumes:
- cache-data:/data
volumes:
cache-data:
$ docker compose up -d # create network + volumes + containers
$ docker compose ps
$ docker compose logs -f web
$ docker compose down # stop + remove (add -v to also drop volumes)
Note: Compose automatically creates a user-defined network for the stack - sowebcan reachcacheby service name. The default-bridge DNS problem simply doesn't exist here.
Tip: Named volumes must be declared twice: under the service (cache-data:/data) and in the top-levelvolumes:key. Forgetting the second is the most common compose error.