docker-compose.yml 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. services:
  2. # 主应用(Web API 服务)- 使用 Nginx + PHP-FPM
  3. app:
  4. build: .
  5. container_name: math_cms_app
  6. # 使用 Dockerfile 中的默认 CMD(nginx + php-fpm)
  7. ports:
  8. - "5019:8000"
  9. env_file:
  10. - .env
  11. volumes:
  12. - ./storage:/app/storage # 日志 + 临时文件 + OCR上传
  13. - ./.env:/app/.env # 环境配置文件
  14. restart: unless-stopped
  15. healthcheck:
  16. test: ["CMD-SHELL", "curl -f http://localhost:8000/health || exit 1"]
  17. interval: 30s
  18. timeout: 10s
  19. retries: 3
  20. start_period: 40s
  21. # 队列 Worker(通用任务队列)
  22. queue:
  23. build: .
  24. container_name: math_cms_queue
  25. command: php artisan queue:work --sleep=3 --tries=3 --max-time=3600
  26. env_file:
  27. - .env
  28. volumes:
  29. - ./storage:/app/storage
  30. - ./.env:/app/.env
  31. restart: unless-stopped
  32. stop_grace_period: 60s
  33. # 队列 worker 健康检查:检查进程是否存在
  34. healthcheck:
  35. test: ["CMD-SHELL", "pgrep -f 'queue:work' || exit 1"]
  36. interval: 30s
  37. timeout: 10s
  38. retries: 3
  39. start_period: 10s
  40. deploy:
  41. resources:
  42. limits:
  43. cpus: '1'
  44. memory: 512M
  45. # PDF 生成专用 Worker(资源隔离,防止 Chrome 吃满 CPU)
  46. pdf-worker:
  47. build: .
  48. container_name: math_cms_pdf
  49. command: php artisan queue:work --queue=pdf --sleep=3 --tries=2 --max-time=300 --max-jobs=10
  50. env_file:
  51. - .env
  52. volumes:
  53. - ./storage:/app/storage
  54. - ./.env:/app/.env
  55. restart: unless-stopped
  56. stop_grace_period: 120s
  57. # PDF worker 健康检查:检查进程是否存在
  58. healthcheck:
  59. test: ["CMD-SHELL", "pgrep -f 'queue:work' || exit 1"]
  60. interval: 30s
  61. timeout: 10s
  62. retries: 3
  63. start_period: 10s
  64. deploy:
  65. resources:
  66. limits:
  67. cpus: '2'
  68. memory: 2G
  69. networks:
  70. default:
  71. driver: bridge