Docker Compose Multi-Container App Example
This practical guide shows how to run an app, database, cache, and admin tool together using Docker Compose. It explains services, networks, volumes, environment variables, health checks, and common troubleshooting steps.
Example architecture
- app: Web application container.
- db: PostgreSQL database.
- redis: Cache service.
- adminer: Database admin UI for local development.
compose.yaml example
services: app: build: . ports: - "3000:3000" environment: DATABASE_URL: postgres://appuser:example@db:5432/appdb REDIS_URL: redis://redis:6379 depends_on: - db - redis db: image: postgres:16 environment: POSTGRES_DB: appdb POSTGRES_USER: appuser POSTGRES_PASSWORD: example volumes: - postgres_data:/var/lib/postgresql/data redis: image: redis:7-alpine adminer: image: adminer ports: - "8080:8080" depends_on: - db volumes: postgres_data:
Run the full stack
docker compose up -d docker compose ps docker compose logs -f app
Open services
- Application:
- Adminer:
Execute commands inside services
docker compose exec app sh docker compose exec db psql -U appuser -d appdb docker compose exec redis redis-cli ping
Stop and clean up
docker compose down # Remove volumes too, only if you want to delete database data docker compose down -v
Health check idea
healthcheck: test: ["CMD-SHELL", "pg_isready -U appuser -d appdb"] interval: 10s timeout: 5s retries: 5
Common mistakes
- Using localhost inside containers instead of service names.
- Not using volumes for database data.
- Exposing database ports publicly when not needed.
- Putting production secrets directly in compose files.
- Assuming startup order means service readiness.
Best practices
- Use service names for internal communication.
- Use named volumes for stateful services.
- Keep development and production Compose files separate.
- Use health checks for critical dependencies.
- Document environment variables clearly.
Related Melochip guides
- Docker Learning Path
- Docker Compose Beginner Guide
- Docker Volumes Explained
Official references
- Docker Compose documentation
Join the discussion
0 CommentsAsk questions, add context, or share what worked.
More from Melochip Editorial
Learn what Playwright testing is, why modern QA teams use it, how testers can get started, and the major types...
7 min read · Sep 19, 2026
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Sep 17, 2026
Learn Kubernetes security best practices with RBAC, Secrets, ServiceAccounts, Pod securityContext, NetworkPoli...
6 min read · Sep 17, 2026Related articles
Learn Docker environment variables and secrets, including docker run -e, env files, Compose environment, secre...
2 min read · Sep 17, 2026
Prepare for Docker interviews with practical questions and real-time scenarios covering images, containers, Do...
2 min read · Sep 17, 2026
Learn Docker registries, image tags, Docker Hub, private registries, login, push, pull, naming rules, CI/CD us...
2 min read · Sep 17, 2026
Learn Docker security best practices for images, containers, users, secrets, registries, scanning, least privi...
2 min read · Sep 17, 2026Stay in the loop. Get new Melochip articles
Receive Melochip article updates when new articles are available. Explicit opt-in only.
No comments yet. Start the discussion.