docker-compose.yml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. services:
  2. # 主应用(Web API 服务)- 使用 Nginx + PHP-FPM
  3. app:
  4. build:
  5. context: .
  6. target: app-runtime
  7. container_name: math_cms_app
  8. # 使用 Dockerfile 中的默认 CMD(nginx + php-fpm)
  9. ports:
  10. - "5019:8000"
  11. env_file:
  12. - .env
  13. volumes:
  14. - ./storage:/app/storage # 日志 + 临时文件 + OCR上传
  15. - ./.env:/app/.env # 环境配置文件
  16. restart: unless-stopped
  17. healthcheck:
  18. test: ["CMD-SHELL", "curl -f http://localhost:8000/health || exit 1"]
  19. interval: 30s
  20. timeout: 10s
  21. retries: 3
  22. start_period: 40s
  23. # 队列 Worker(通用任务队列)
  24. queue:
  25. build:
  26. context: .
  27. target: app-runtime
  28. container_name: math_cms_queue
  29. command: php artisan queue:work --sleep=3 --tries=3 --max-time=3600
  30. env_file:
  31. - .env
  32. volumes:
  33. - ./storage:/app/storage
  34. - ./.env:/app/.env
  35. restart: unless-stopped
  36. stop_grace_period: 60s
  37. # 队列 worker 健康检查:检查进程是否存在
  38. healthcheck:
  39. test: ["CMD-SHELL", "pgrep -f 'queue:work' || exit 1"]
  40. interval: 30s
  41. timeout: 10s
  42. retries: 3
  43. start_period: 10s
  44. deploy:
  45. resources:
  46. limits:
  47. cpus: '1'
  48. memory: 512M
  49. # Gotenberg PDF 转换服务(内网访问,不暴露公网端口)
  50. gotenberg:
  51. image: gotenberg/gotenberg:8
  52. container_name: math_cms_gotenberg
  53. restart: unless-stopped
  54. healthcheck:
  55. test: ["CMD-SHELL", "curl -fsS http://localhost:3000/health >/dev/null || exit 1"]
  56. interval: 30s
  57. timeout: 10s
  58. retries: 3
  59. start_period: 20s
  60. deploy:
  61. resources:
  62. limits:
  63. cpus: '2'
  64. memory: 1536M
  65. # PDF 生成专用 Worker(资源隔离,防止 Chrome 吃满 CPU)
  66. pdf-worker:
  67. build:
  68. context: .
  69. target: pdfworker
  70. container_name: math_cms_pdf
  71. command: php artisan queue:work --queue=pdf --sleep=3 --tries=2 --max-time=300 --max-jobs=10
  72. env_file:
  73. - .env
  74. volumes:
  75. - ./storage:/app/storage
  76. - ./.env:/app/.env
  77. restart: unless-stopped
  78. stop_grace_period: 120s
  79. depends_on:
  80. gotenberg:
  81. condition: service_healthy
  82. # PDF worker 健康检查:检查进程是否存在
  83. healthcheck:
  84. test: ["CMD-SHELL", "pgrep -f 'queue:work' || exit 1"]
  85. interval: 30s
  86. timeout: 10s
  87. retries: 3
  88. start_period: 10s
  89. deploy:
  90. resources:
  91. limits:
  92. cpus: '2'
  93. memory: 2G
  94. networks:
  95. default:
  96. driver: bridge