# ============================================================================ # FlowSentinel - Docker Compose Configuration # ============================================================================ # This docker-compose file provides easy development and deployment setup. # # Usage: # Development (with hot reload): docker-compose up # Production: docker-compose -f docker-compose.yml up # Build from scratch: docker-compose build --no-cache # Stop services: docker-compose down # Database only: docker-compose up postgres # ============================================================================ version: '3.8' services: # -------------------------------------------------------------------------- # PostgreSQL Database Service # -------------------------------------------------------------------------- postgres: image: postgres:15-alpine container_name: flowsentinel-db # PostgreSQL configuration environment: POSTGRES_USER: flowsentinel POSTGRES_PASSWORD: flowsentinel123 POSTGRES_DB: flowsentinel PGDATA: /var/lib/postgresql/data/pgdata # Port mapping (host:container) ports: - "5432:5432" # Persistent data storage volumes: - flowsentinel-db-data:/var/lib/postgresql/data - ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql # Health check healthcheck: test: ["CMD-SHELL", "pg_isready -U flowsentinel -d flowsentinel"] interval: 10s timeout: 5s retries: 5 start_period: 10s # Restart policy restart: unless-stopped # Network networks: - flowsentinel-network # Logging logging: driver: "json-file" options: max-size: "10m" max-file: "3" # -------------------------------------------------------------------------- # FlowSentinel Backend Service # -------------------------------------------------------------------------- flowsentinel-backend: # Build configuration build: context: . dockerfile: Dockerfile # Container name container_name: flowsentinel-api # Port mapping (host:container) ports: - "8000:8000" # Environment variables # Option 1: Load from .env file (recommended) env_file: - .env # Option 2: Specify environment variables directly (uncomment if needed) environment: - DATABASE_URL=postgresql://flowsentinel:flowsentinel123@postgres:5432/flowsentinel # Depends on database depends_on: postgres: condition: service_healthy # Volume mounts for development (hot reload) # Comment out for production deployment volumes: - ./src:/app/src - ./tests:/app/tests # Note: .env is NOT mounted for security (use env_file instead) # Health check configuration healthcheck: test: ["CMD", "python", "-c", "import requests; requests.get('http://localhost:8000/health', timeout=3)"] interval: 30s timeout: 5s retries: 3 start_period: 10s # Restart policy restart: unless-stopped # Resource limits (optional, adjust based on your needs) deploy: resources: limits: cpus: '1.0' memory: 512M reservations: cpus: '0.5' memory: 256M # Network configuration networks: - flowsentinel-network # Logging configuration logging: driver: "json-file" options: max-size: "10m" max-file: "3" # -------------------------------------------------------------------------- # Networks # -------------------------------------------------------------------------- networks: flowsentinel-network: driver: bridge name: flowsentinel-network # -------------------------------------------------------------------------- # Volumes (for persistent storage) # -------------------------------------------------------------------------- volumes: flowsentinel-db-data: name: flowsentinel-db-data driver: local