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.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 - so web can reach cache by 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-level volumes: key. Forgetting the second is the most common compose error.