# Enhanced Docker Compose for Foxhunt HFT Trading System # Production-ready configuration with comprehensive health checks, networking, and monitoring version: '3.8' networks: foxhunt-network: driver: bridge ipam: config: - subnet: 172.20.0.0/24 gateway: 172.20.0.1 volumes: postgres-data: driver: local redis-data: driver: local influxdb-data: driver: local prometheus-data: driver: local grafana-data: driver: local clickhouse-data: driver: local services: # PostgreSQL - Main database for trades, orders, positions postgres: image: postgres:15-alpine container_name: foxhunt-postgres hostname: postgres networks: foxhunt-network: ipv4_address: 172.20.0.10 ports: - "${POSTGRES_PORT:-5432}:5432" volumes: - postgres-data:/var/lib/postgresql/data - ../migrations:/docker-entrypoint-initdb.d:ro - ../config/postgres:/etc/postgresql:ro environment: POSTGRES_DB: ${POSTGRES_DB:-foxhunt} POSTGRES_USER: ${POSTGRES_USER:-foxhunt} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD required} POSTGRES_INITDB_ARGS: "--encoding=UTF8 --locale=C" command: > postgres -c shared_preload_libraries=pg_stat_statements -c max_connections=200 -c shared_buffers=256MB -c effective_cache_size=1GB -c maintenance_work_mem=64MB -c checkpoint_completion_target=0.9 -c wal_buffers=16MB -c default_statistics_target=100 -c random_page_cost=1.1 -c effective_io_concurrency=200 healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-foxhunt} -d ${POSTGRES_DB:-foxhunt}"] interval: 10s timeout: 5s retries: 5 start_period: 30s restart: unless-stopped deploy: resources: limits: memory: 1G cpus: '1.0' reservations: memory: 512M cpus: '0.5' # Redis - Cache and pub/sub for real-time data redis: image: redis:7-alpine container_name: foxhunt-redis hostname: redis networks: foxhunt-network: ipv4_address: 172.20.0.11 ports: - "${REDIS_PORT:-6379}:6379" volumes: - redis-data:/data - ../config/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro command: > redis-server /usr/local/etc/redis/redis.conf --appendonly yes --requirepass ${REDIS_PASSWORD:?REDIS_PASSWORD required} --maxmemory 512mb --maxmemory-policy allkeys-lru healthcheck: test: ["CMD", "redis-cli", "--no-auth-warning", "-a", "${REDIS_PASSWORD}", "ping"] interval: 10s timeout: 3s retries: 3 start_period: 10s restart: unless-stopped deploy: resources: limits: memory: 768M cpus: '0.5' reservations: memory: 256M cpus: '0.25' # InfluxDB - Time-series database for market data influxdb: image: influxdb:2.7-alpine container_name: foxhunt-influxdb hostname: influxdb networks: foxhunt-network: ipv4_address: 172.20.0.12 ports: - "${INFLUXDB_PORT:-8086}:8086" volumes: - influxdb-data:/var/lib/influxdb2 - ../config/influxdb:/etc/influxdb2:ro environment: DOCKER_INFLUXDB_INIT_MODE: setup DOCKER_INFLUXDB_INIT_USERNAME: ${INFLUXDB_USER:-admin} DOCKER_INFLUXDB_INIT_PASSWORD: ${INFLUXDB_PASSWORD:?INFLUXDB_PASSWORD required} DOCKER_INFLUXDB_INIT_ORG: ${INFLUXDB_ORG:-foxhunt} DOCKER_INFLUXDB_INIT_BUCKET: ${INFLUXDB_BUCKET:-market_data} DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: ${INFLUXDB_TOKEN:?INFLUXDB_TOKEN required} INFLUXD_SESSION_LENGTH: 60 healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8086/ping"] interval: 10s timeout: 5s retries: 3 start_period: 30s restart: unless-stopped deploy: resources: limits: memory: 2G cpus: '1.0' reservations: memory: 512M cpus: '0.5' # ClickHouse - High-performance analytics database clickhouse: image: clickhouse/clickhouse-server:23.8-alpine container_name: foxhunt-clickhouse hostname: clickhouse networks: foxhunt-network: ipv4_address: 172.20.0.13 ports: - "${CLICKHOUSE_HTTP_PORT:-8123}:8123" - "${CLICKHOUSE_TCP_PORT:-9000}:9000" volumes: - clickhouse-data:/var/lib/clickhouse - ../config/clickhouse:/etc/clickhouse-server/config.d:ro environment: CLICKHOUSE_DB: ${CLICKHOUSE_DB:-foxhunt} CLICKHOUSE_USER: ${CLICKHOUSE_USER:-default} CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:?CLICKHOUSE_PASSWORD required} healthcheck: test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8123/ping"] interval: 10s timeout: 5s retries: 3 start_period: 30s restart: unless-stopped deploy: resources: limits: memory: 4G cpus: '2.0' reservations: memory: 1G cpus: '1.0' # Prometheus - Metrics collection and monitoring prometheus: image: prom/prometheus:v2.47.0 container_name: foxhunt-prometheus hostname: prometheus networks: foxhunt-network: ipv4_address: 172.20.0.20 ports: - "${PROMETHEUS_PORT:-9090}:9090" volumes: - prometheus-data:/prometheus - ../config/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro - ../config/prometheus/rules:/etc/prometheus/rules:ro command: - '--config.file=/etc/prometheus/prometheus.yml' - '--storage.tsdb.path=/prometheus' - '--web.console.libraries=/usr/share/prometheus/console_libraries' - '--web.console.templates=/usr/share/prometheus/consoles' - '--web.enable-lifecycle' - '--web.enable-admin-api' - '--storage.tsdb.retention.time=30d' - '--storage.tsdb.retention.size=10GB' healthcheck: test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:9090/-/ready"] interval: 10s timeout: 5s retries: 3 start_period: 20s restart: unless-stopped deploy: resources: limits: memory: 2G cpus: '1.0' reservations: memory: 512M cpus: '0.5' # Grafana - Monitoring dashboards and visualization grafana: image: grafana/grafana:10.1.0 container_name: foxhunt-grafana hostname: grafana networks: foxhunt-network: ipv4_address: 172.20.0.21 ports: - "${GRAFANA_PORT:-3000}:3000" volumes: - grafana-data:/var/lib/grafana - ../config/grafana/provisioning:/etc/grafana/provisioning:ro - ../config/grafana/dashboards:/var/lib/grafana/dashboards:ro environment: GF_SECURITY_ADMIN_USER: ${GRAFANA_ADMIN_USER:-admin} GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:?GRAFANA_ADMIN_PASSWORD required} GF_INSTALL_PLUGINS: grafana-clock-panel,grafana-simple-json-datasource GF_SERVER_ROOT_URL: http://localhost:3000 GF_ANALYTICS_REPORTING_ENABLED: false GF_ANALYTICS_CHECK_FOR_UPDATES: false healthcheck: test: ["CMD-SHELL", "curl -f http://localhost:3000/api/health || exit 1"] interval: 10s timeout: 5s retries: 3 start_period: 30s restart: unless-stopped deploy: resources: limits: memory: 1G cpus: '0.5' reservations: memory: 256M cpus: '0.25' depends_on: prometheus: condition: service_healthy # Node Exporter - System metrics for monitoring node-exporter: image: prom/node-exporter:v1.6.1 container_name: foxhunt-node-exporter hostname: node-exporter networks: foxhunt-network: ipv4_address: 172.20.0.22 ports: - "9100:9100" command: - '--path.procfs=/host/proc' - '--path.sysfs=/host/sys' - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)' volumes: - /proc:/host/proc:ro - /sys:/host/sys:ro - /:/rootfs:ro restart: unless-stopped deploy: resources: limits: memory: 128M cpus: '0.1' reservations: memory: 64M cpus: '0.05' # Cadvisor - Container metrics cadvisor: image: gcr.io/cadvisor/cadvisor:v0.47.2 container_name: foxhunt-cadvisor hostname: cadvisor networks: foxhunt-network: ipv4_address: 172.20.0.23 ports: - "8080:8080" volumes: - /:/rootfs:ro - /var/run:/var/run:ro - /sys:/sys:ro - /var/lib/docker/:/var/lib/docker:ro - /dev/disk/:/dev/disk:ro privileged: true devices: - /dev/kmsg restart: unless-stopped deploy: resources: limits: memory: 256M cpus: '0.2' reservations: memory: 128M cpus: '0.1' # Jaeger - Distributed tracing jaeger: image: jaegertracing/all-in-one:1.49 container_name: foxhunt-jaeger hostname: jaeger networks: foxhunt-network: ipv4_address: 172.20.0.30 ports: - "16686:16686" # Jaeger UI - "14268:14268" # Jaeger collector HTTP environment: COLLECTOR_OTLP_ENABLED: true restart: unless-stopped deploy: resources: limits: memory: 512M cpus: '0.5' reservations: memory: 256M cpus: '0.25' # Health check service for overall stack health healthcheck: image: alpine:3.18 container_name: foxhunt-healthcheck networks: - foxhunt-network command: > sh -c " apk add --no-cache curl && while true; do echo 'Checking service health...' curl -f http://postgres:5432 || echo 'PostgreSQL check failed' curl -f http://redis:6379 || echo 'Redis check failed' curl -f http://influxdb:8086/ping || echo 'InfluxDB check failed' curl -f http://prometheus:9090/-/ready || echo 'Prometheus check failed' curl -f http://grafana:3000/api/health || echo 'Grafana check failed' sleep 30 done " restart: unless-stopped depends_on: postgres: condition: service_healthy redis: condition: service_healthy influxdb: condition: service_healthy prometheus: condition: service_healthy grafana: condition: service_healthy