services: postgres: image: postgres:16.4-alpine environment: POSTGRES_USER: ${POSTGRES_USER:-messenger} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Copy .env.example to .env and set POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB:-messenger} volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U \"$${POSTGRES_USER}\" -d \"$${POSTGRES_DB}\""] interval: 5s timeout: 3s retries: 20 start_period: 5s restart: unless-stopped redis: image: redis:7.4.2-alpine command: ["redis-server", "--save", "", "--appendonly", "no", "--maxmemory", "128mb", "--maxmemory-policy", "allkeys-lru"] healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 20 restart: unless-stopped api: build: context: . dockerfile: Dockerfile environment: APP_HOST: 0.0.0.0 APP_PORT: 8080 DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-messenger} CACHE_URL: redis://redis:6379/0 SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} DB_POOL_MAX_SIZE: ${DB_POOL_MAX_SIZE:-16} DB_POOL_TIMEOUT_SECONDS: ${DB_POOL_TIMEOUT_SECONDS:-5} DB_STATEMENT_TIMEOUT_MS: ${DB_STATEMENT_TIMEOUT_MS:-5000} DB_LOCK_TIMEOUT_MS: ${DB_LOCK_TIMEOUT_MS:-2000} ports: - "127.0.0.1:${APP_PORT:-8080}:8080" depends_on: postgres: condition: service_healthy redis: condition: service_healthy healthcheck: test: - CMD - python3 - -c - "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2).read()" interval: 5s timeout: 3s retries: 20 start_period: 10s restart: unless-stopped volumes: postgres_data: