
The Docker Compose Template I Start Every Project With
I've written 50+ docker-compose files. This is what they all converge to. Every new project starts with this template. It covers 90% of use cases. version : ' 3.8' services : app : build : . ports : - " 8000:8000" environment : - DATABASE_URL=postgresql://postgres:postgres@db:5432/app - REDIS_URL=redis://cache:6379/0 depends_on : db : condition : service_healthy cache : condition : service_started volumes : - .:/app restart : unless-stopped healthcheck : test : curl -f http://localhost:8000/health || exit 1 interval : 30s timeout : 10s retries : 3 db : image : postgres:16-alpine environment : POSTGRES_DB : app POSTGRES_USER : postgres POSTGRES_PASSWORD : postgres ports : - " 5432:5432" volumes : - pgdata:/var/lib/postgresql/data healthcheck : test : pg_isready -U postgres interval : 5s timeout : 5s retries : 5 cache : image : redis:7-alpine ports : - " 6379:6379" volumes : - redisdata:/data volumes : pgdata : redisdata : Why this template works 1. Health checks with depends_on conditio
Continue reading on Dev.to Tutorial
Opens in a new tab




