Docker Compose lets you define and run multi-container applications with a single command. A practical guide from development setup to integration tests.
From Dockerfile to an entire application¶
Docker solved the “works on my machine” problem for individual containers. Docker Compose
goes further — it defines the entire application stack in a single YAML file. Web server,
database, cache, message broker — all started with one docker-compose up.
Compose is a key tool for local development and CI/CD pipelines. Every developer gets an identical environment within seconds.
Anatomy of docker-compose.yml¶
A typical web application in Compose:
version: '2'
services:
web:
build: .
ports:
- "8080:80"
volumes:
- ./src:/app/src
depends_on:
- db
- redis
environment:
DATABASE_URL: postgres://user:pass@db:5432/app
db:
image: postgres:9.5
volumes:
- pgdata:/var/lib/postgresql/data
redis:
image: redis:3-alpine
volumes:
pgdata:
Services, networks, and volumes — the three pillars of Compose configuration.
Development workflow with Compose¶
Compose transforms the onboarding of new developers:
git clone+docker-compose up= a working environment- Hot reload via bind mounts (
volumes) - Isolated databases — no conflicts between projects
docker-compose run web pytestfor tests in the same environment
For CI/CD pipelines, docker-compose -f docker-compose.test.yml up --abort-on-container-exit
is all you need to run integration tests.
Best practices and tips¶
A few proven rules:
- Use a
.envfile for environment variables - Define health checks for reliable
depends\_on - Separate production and development override files (
docker-compose.override.yml) - Name volumes to persist data across restarts
- Use
docker-compose logs -f service\_namefor debugging
Conclusion: the standard for local development¶
Docker Compose is becoming the de facto standard for local development environments. It eliminates “works on my machine” problems, speeds up onboarding, and ensures consistency between development and production. Every project should have its own docker-compose.yml.
Need help with implementation?
Our experts can help with design, implementation, and operations. From architecture to production.
Contact us