Overview
This compose file gives every developer a consistent local environment without installing Postgres or Redis globally.
docker-compose.yml
name: myapp-dev
services:
app:
build: .
ports:
- "3000:3000"
env_file: .env.local
depends_on:
db:
condition: service_healthy
cache:
condition: service_started
volumes:
- .:/app
- /app/node_modules # anonymous volume keeps container modules
db:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:-appdb}
POSTGRES_USER: ${POSTGRES_USER:-app}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-secret}
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
- ./data:/docker-entrypoint-initdb.d # auto-runs *.sql on first boot
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER}"]
interval: 5s
timeout: 5s
retries: 10
cache:
image: redis:7-alpine
restart: unless-stopped
command: redis-server --save 60 1 --loglevel warning
ports:
- "6379:6379"
volumes:
- redisdata:/data
adminer:
image: adminer
restart: unless-stopped
ports:
- "8080:8080"
profiles: [tools] # start only with: docker compose --profile tools up
volumes:
pgdata:
redisdata:
Usage
# Start everything
docker compose up -d
# Start with Adminer UI
docker compose --profile tools up -d
# Tail app logs
docker compose logs -f app
Notes
- The
./datadirectory is mounted toinitdb.d— any.sqlfiles run automatically when the volume is first created. Point this at yourdata/SQL seed files. - Use
POSTGRES_*vars in.env.localto keep credentials out of source control.