version: "3.8" services: app: build: . ports: - "3000:3000" # Expose app on host port 3000 depends_on: db: condition: service_healthy # Wait for DB to be healthy redis: condition: service_started # Wait for Redis to start environment: - DB_HOST=${DB_HOST} - DB_USER=${DB_USER} - DB_PASSWORD=${DB_PASSWORD} - DB_NAME=${DB_NAME} - PORT=${PORT} - REDIS_HOST=${REDIS_HOST:-redis} - REDIS_PORT=${REDIS_PORT:-6379} - REDIS_PASSWORD=${REDIS_PASSWORD:-} restart: unless-stopped db: image: postgres:15-alpine ports: - "5432:5432" # Standard PostgreSQL port environment: POSTGRES_USER: ${DB_USER} POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_DB: ${DB_NAME} volumes: - pg_data:/var/lib/postgresql/data # Persist database data - ./init.sql:/docker-entrypoint-initdb.d/init.sql # Run init script on startup healthcheck: test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME} -h localhost"] interval: 10s timeout: 5s retries: 5 restart: unless-stopped redis: image: redis:7-alpine ports: - "6380:6379" # Expose Redis on host port 6380 (to avoid conflict if you have local Redis on 6379) command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD:-} volumes: - redis_data:/data # Persist Redis data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 10s timeout: 5s retries: 5 restart: unless-stopped volumes: pg_data: redis_data: