url-shortner/docker-compose.yml

62 lines
1.3 KiB
YAML

services:
# PostgreSQL - Primary database
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: urlshortner
POSTGRES_PASSWORD: localdev
POSTGRES_DB: urlshortner
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./db/init.sql:/docker-entrypoint-initdb.d/init.sql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U urlshortner"]
interval: 5s
timeout: 5s
retries: 5
# Redis - Caching layer
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 5s
retries: 5
# API Server (can scale with --scale api=3)
api:
build:
context: .
dockerfile: Dockerfile
environment:
DATABASE_URL: postgresql://urlshortner:localdev@postgres:5432/urlshortner
REDIS_URL: redis://redis:6379
MACHINE_ID: 1
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "8000" # Random port mapping for scaling
# Nginx - Load balancer
nginx:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- api
volumes:
postgres_data:
redis_data: