Docker Compose for Multi-Container Systems
Real applications are never a single container. You have web frontends, API backends, PostgreSQL databases, Redis caches, and background workers. Docker Compose lets you define and run the entire stack with…
Lesson 7 of 26 · Module: Docker
22 min read · Source notes — Docker Compose & Full-Stack Application
Real applications are never a single container. You have web frontends, API backends, PostgreSQL databases, Redis caches, and background workers. Docker Compose lets you define and run the entire stack with a single declarative YAML file.

Instructor mapping multi-tier services, isolated bridge networks, and persistent volume attachments.
Full Production docker-compose.yml Example
Microservices Stack: Frontend + Node API + Postgres + Redis
version: '3.8'
services:
# 1. Reverse Proxy & Frontend
web:
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- "80:80"
depends_on:
api:
condition: service_healthy
networks:
- frontend-net
# 2. Backend API Service
api:
build:
context: ./backend
dockerfile: Dockerfile
environment:
NODE_ENV: production
DATABASE_URL: postgres://dbuser:secretpass@postgres:5432/appdb
REDIS_URL: redis://cache:6379
depends_on:
postgres:
condition: service_healthy
cache:
condition: service_started
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 10s
timeout: 5s
retries: 3
networks:
- frontend-net
- backend-net
# 3. Relational Database with Persistent Volume
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: appdb
POSTGRES_USER: dbuser
POSTGRES_PASSWORD: secretpass
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U dbuser -d appdb"]
interval: 5s
timeout: 5s
retries: 5
networks:
- backend-net
# 4. Redis In-Memory Cache
cache:
image: redis:7-alpine
command: redis-server --appendonly yes
volumes:
- redisdata:/data
networks:
- backend-net
networks:
frontend-net:
driver: bridge
backend-net:
driver: bridge
volumes:
pgdata:
driver: local
redisdata:
driver: local
Demonstrating that container recreation preserves database data through named volumes.
Quick Knowledge Check
In Docker Compose, how do containers within the same user-defined network communicate with one another?
Keep going: ← Lesson 6 · Lesson 8 → · Module overview · Track it in the Self Guide
Finished this one?
Part of Self Guide · Stage 3: Containers with Docker. Progress is saved in this browser.



