docker-compose.yml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. # Gotenberg PDF 转换服务(内网访问,不暴露公网端口)
  46. gotenberg:
  47. image: gotenberg/gotenberg:8
  48. container_name: math_cms_gotenberg
  49. restart: unless-stopped
  50. healthcheck:
  51. test: ["CMD-SHELL", "curl -fsS http://localhost:3000/health >/dev/null || exit 1"]
  52. interval: 30s
  53. timeout: 10s
  54. retries: 3
  55. start_period: 20s
  56. deploy:
  57. resources:
  58. limits:
  59. cpus: '2'
  60. memory: 1536M
  61. # PDF 生成专用 Worker(资源隔离,防止 Chrome 吃满 CPU)
  62. pdf-worker:
  63. build: .
  64. container_name: math_cms_pdf
  65. command: php artisan queue:work --queue=pdf --sleep=3 --tries=2 --max-time=300 --max-jobs=10
  66. env_file:
  67. - .env
  68. volumes:
  69. - ./storage:/app/storage
  70. - ./.env:/app/.env
  71. restart: unless-stopped
  72. stop_grace_period: 120s
  73. depends_on:
  74. gotenberg:
  75. condition: service_healthy
  76. # PDF worker 健康检查:检查进程是否存在
  77. healthcheck:
  78. test: ["CMD-SHELL", "pgrep -f 'queue:work' || exit 1"]
  79. interval: 30s
  80. timeout: 10s
  81. retries: 3
  82. start_period: 10s
  83. deploy:
  84. resources:
  85. limits:
  86. cpus: '2'
  87. memory: 2G
  88. networks:
  89. default:
  90. driver: bridge