services: postgres: image: postgres:16 environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres} POSTGRES_DB: ai_chat ports: # 宿主 5433 映射,避免和你本机 5432 的 Postgres 冲突 - "5433:5432" volumes: - pgdata:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 5s timeout: 3s retries: 10 redis: image: redis:7 ports: - "6380:6379" healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 10 rabbitmq: image: rabbitmq:3-management ports: - "5672:5672" # AMQP - "15672:15672" # 管理界面 http://localhost:15672 guest/guest healthcheck: test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"] interval: 10s timeout: 5s retries: 10 api: build: . ports: - "8000:8000" environment: DATABASE_URL: postgresql+asyncpg://postgres:${POSTGRES_PASSWORD:-postgres}@postgres:5432/ai_chat REDIS_URL: redis://redis:6379/0 RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672/ JWT_SECRET: ${JWT_SECRET:-dev-secret} LLM_BASE_URL: ${LLM_BASE_URL} LLM_API_KEY: ${LLM_API_KEY} LLM_MODEL: ${LLM_MODEL} depends_on: postgres: condition: service_healthy redis: condition: service_healthy rabbitmq: condition: service_healthy worker: build: . command: python -m app.worker environment: DATABASE_URL: postgresql+asyncpg://postgres:${POSTGRES_PASSWORD:-postgres}@postgres:5432/ai_chat REDIS_URL: redis://redis:6379/0 RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672/ LLM_BASE_URL: ${LLM_BASE_URL} LLM_API_KEY: ${LLM_API_KEY} LLM_MODEL: ${LLM_MODEL} depends_on: postgres: condition: service_healthy rabbitmq: condition: service_healthy volumes: pgdata: