docker-compose.yml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. version: '3.8'
  2. services:
  3. # 后端服务
  4. backend:
  5. build:
  6. context: ../backend
  7. dockerfile: Dockerfile
  8. container_name: tolan-backend
  9. restart: unless-stopped
  10. ports:
  11. - "8765:8765"
  12. environment:
  13. - DEBUG=false
  14. - LOG_LEVEL=INFO
  15. - HOST=0.0.0.0
  16. - PORT=8765
  17. env_file:
  18. - ../backend/.env
  19. volumes:
  20. - ../backend/logs:/app/logs
  21. - /tmp/tolan:/tmp/tolan
  22. networks:
  23. - tolan-network
  24. healthcheck:
  25. test: ["CMD", "python", "-c", "import socket; socket.create_connection(('localhost', 8765), timeout=5)"]
  26. interval: 30s
  27. timeout: 10s
  28. retries: 3
  29. start_period: 40s
  30. depends_on:
  31. - redis
  32. logging:
  33. driver: "json-file"
  34. options:
  35. max-size: "10m"
  36. max-file: "3"
  37. # 前端服务 (Nginx)
  38. frontend:
  39. build:
  40. context: ../frontend
  41. dockerfile: Dockerfile.prod
  42. args:
  43. - REACT_APP_WS_URL=ws://localhost:8765
  44. - REACT_APP_ENV=production
  45. container_name: tolan-frontend
  46. restart: unless-stopped
  47. ports:
  48. - "80:80"
  49. - "443:443"
  50. volumes:
  51. - ./nginx.conf:/etc/nginx/nginx.conf:ro
  52. - ./ssl:/etc/ssl/certs:ro
  53. - nginx-logs:/var/log/nginx
  54. networks:
  55. - tolan-network
  56. depends_on:
  57. - backend
  58. logging:
  59. driver: "json-file"
  60. options:
  61. max-size: "10m"
  62. max-file: "3"
  63. # Redis 缓存服务 (可选)
  64. redis:
  65. image: redis:7-alpine
  66. container_name: tolan-redis
  67. restart: unless-stopped
  68. ports:
  69. - "6379:6379"
  70. volumes:
  71. - redis-data:/data
  72. networks:
  73. - tolan-network
  74. command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
  75. healthcheck:
  76. test: ["CMD", "redis-cli", "ping"]
  77. interval: 30s
  78. timeout: 10s
  79. retries: 3
  80. logging:
  81. driver: "json-file"
  82. options:
  83. max-size: "5m"
  84. max-file: "2"
  85. # 监控服务 (Prometheus)
  86. prometheus:
  87. image: prom/prometheus:latest
  88. container_name: tolan-prometheus
  89. restart: unless-stopped
  90. ports:
  91. - "9090:9090"
  92. volumes:
  93. - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
  94. - prometheus-data:/prometheus
  95. networks:
  96. - tolan-network
  97. command:
  98. - '--config.file=/etc/prometheus/prometheus.yml'
  99. - '--storage.tsdb.path=/prometheus'
  100. - '--web.console.libraries=/etc/prometheus/console_libraries'
  101. - '--web.console.templates=/etc/prometheus/consoles'
  102. - '--storage.tsdb.retention.time=200h'
  103. - '--web.enable-lifecycle'
  104. logging:
  105. driver: "json-file"
  106. options:
  107. max-size: "5m"
  108. max-file: "2"
  109. # 日志聚合 (可选)
  110. filebeat:
  111. image: docker.elastic.co/beats/filebeat:8.8.0
  112. container_name: tolan-filebeat
  113. restart: unless-stopped
  114. user: root
  115. volumes:
  116. - ./filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
  117. - /var/lib/docker/containers:/var/lib/docker/containers:ro
  118. - /var/run/docker.sock:/var/run/docker.sock:ro
  119. - filebeat-data:/usr/share/filebeat/data
  120. networks:
  121. - tolan-network
  122. depends_on:
  123. - backend
  124. - frontend
  125. logging:
  126. driver: "json-file"
  127. options:
  128. max-size: "5m"
  129. max-file: "2"
  130. networks:
  131. tolan-network:
  132. driver: bridge
  133. ipam:
  134. config:
  135. - subnet: 172.20.0.0/16
  136. volumes:
  137. redis-data:
  138. driver: local
  139. prometheus-data:
  140. driver: local
  141. nginx-logs:
  142. driver: local
  143. filebeat-data:
  144. driver: local