docker-compose.yml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. version: '3.8'
  2. services:
  3. # PostgreSQL数据库
  4. postgres:
  5. image: postgres:15-alpine
  6. container_name: ai_chat_postgres
  7. environment:
  8. POSTGRES_USER: postgres
  9. POSTGRES_PASSWORD: password
  10. POSTGRES_DB: ai_chat_app
  11. ports:
  12. - "5432:5432"
  13. volumes:
  14. - postgres_data:/var/lib/postgresql/data
  15. networks:
  16. - ai_chat_network
  17. # Redis缓存
  18. redis:
  19. image: redis:7-alpine
  20. container_name: ai_chat_redis
  21. command: redis-server --appendonly yes
  22. ports:
  23. - "6379:6379"
  24. volumes:
  25. - redis_data:/data
  26. networks:
  27. - ai_chat_network
  28. # FastAPI后端
  29. backend:
  30. build: ./backend
  31. container_name: ai_chat_backend
  32. command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
  33. ports:
  34. - "8000:8000"
  35. volumes:
  36. - ./backend:/app
  37. environment:
  38. - DATABASE_URL=postgresql+asyncpg://postgres:password@postgres:5432/ai_chat_app
  39. - DATABASE_URL_SYNC=postgresql://postgres:password@postgres:5432/ai_chat_app
  40. - REDIS_URL=redis://redis:6379/0
  41. - CELERY_BROKER_URL=redis://redis:6379/0
  42. - CELERY_RESULT_BACKEND=redis://redis:6379/0
  43. depends_on:
  44. - postgres
  45. - redis
  46. networks:
  47. - ai_chat_network
  48. # Celery Worker
  49. celery_worker:
  50. build: ./backend
  51. container_name: ai_chat_celery_worker
  52. command: celery -A app.tasks.celery_app worker --loglevel=info
  53. volumes:
  54. - ./backend:/app
  55. environment:
  56. - DATABASE_URL=postgresql+asyncpg://postgres:password@postgres:5432/ai_chat_app
  57. - DATABASE_URL_SYNC=postgresql://postgres:password@postgres:5432/ai_chat_app
  58. - REDIS_URL=redis://redis:6379/0
  59. - CELERY_BROKER_URL=redis://redis:6379/0
  60. - CELERY_RESULT_BACKEND=redis://redis:6379/0
  61. depends_on:
  62. - postgres
  63. - redis
  64. networks:
  65. - ai_chat_network
  66. # Celery Beat
  67. celery_beat:
  68. build: ./backend
  69. container_name: ai_chat_celery_beat
  70. command: celery -A app.tasks.celery_app beat --loglevel=info
  71. volumes:
  72. - ./backend:/app
  73. environment:
  74. - REDIS_URL=redis://redis:6379/0
  75. - CELERY_BROKER_URL=redis://redis:6379/0
  76. depends_on:
  77. - redis
  78. networks:
  79. - ai_chat_network
  80. networks:
  81. ai_chat_network:
  82. driver: bridge
  83. volumes:
  84. postgres_data:
  85. redis_data: