docker-compose.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. # 源码挂载:宿主机改 PHP/Blade 立即进容器(否则镜像内仍是旧代码,改什么都不生效)
  15. - .:/app
  16. - /app/vendor
  17. - /app/node_modules
  18. - /app/public/build
  19. - ./storage:/app/storage
  20. - ./.env:/app/.env
  21. - ./docker/nginx.conf:/etc/nginx/nginx.conf:ro
  22. restart: unless-stopped
  23. healthcheck:
  24. test: ["CMD-SHELL", "curl -f http://localhost:8000/health || exit 1"]
  25. interval: 30s
  26. timeout: 10s
  27. retries: 3
  28. start_period: 40s
  29. # 队列 Worker(通用任务队列)
  30. queue:
  31. build:
  32. context: .
  33. target: app-runtime
  34. container_name: math_cms_queue
  35. command: php artisan queue:work --sleep=3 --tries=3 --max-time=3600
  36. env_file:
  37. - .env
  38. volumes:
  39. - .:/app
  40. - /app/vendor
  41. - /app/node_modules
  42. - /app/public/build
  43. - ./storage:/app/storage
  44. - ./.env:/app/.env
  45. restart: unless-stopped
  46. stop_grace_period: 60s
  47. # 队列 worker 健康检查:检查进程是否存在
  48. healthcheck:
  49. test: ["CMD-SHELL", "pgrep -f 'queue:work' || exit 1"]
  50. interval: 30s
  51. timeout: 10s
  52. retries: 3
  53. start_period: 10s
  54. deploy:
  55. resources:
  56. limits:
  57. cpus: '1'
  58. memory: 512M
  59. # Gotenberg PDF 转换服务(内网访问,不暴露公网端口)
  60. gotenberg:
  61. image: gotenberg/gotenberg:8
  62. container_name: math_cms_gotenberg
  63. restart: unless-stopped
  64. healthcheck:
  65. test: ["CMD-SHELL", "curl -fsS http://localhost:3000/health >/dev/null || exit 1"]
  66. interval: 30s
  67. timeout: 10s
  68. retries: 3
  69. start_period: 20s
  70. deploy:
  71. resources:
  72. limits:
  73. cpus: '2'
  74. memory: 1536M
  75. # PDF 生成专用 Worker(资源隔离,防止 Chrome 吃满 CPU)
  76. pdf-worker:
  77. build:
  78. context: .
  79. target: pdfworker
  80. container_name: math_cms_pdf
  81. command: php artisan queue:work --queue=pdf --sleep=3 --tries=2 --max-time=300 --max-jobs=10
  82. env_file:
  83. - .env
  84. volumes:
  85. - .:/app
  86. - /app/vendor
  87. - /app/node_modules
  88. - /app/public/build
  89. - ./storage:/app/storage
  90. - ./.env:/app/.env
  91. restart: unless-stopped
  92. stop_grace_period: 120s
  93. depends_on:
  94. gotenberg:
  95. condition: service_healthy
  96. # PDF worker 健康检查:检查进程是否存在
  97. healthcheck:
  98. test: ["CMD-SHELL", "pgrep -f 'queue:work' || exit 1"]
  99. interval: 30s
  100. timeout: 10s
  101. retries: 3
  102. start_period: 10s
  103. deploy:
  104. resources:
  105. limits:
  106. cpus: '2'
  107. memory: 2G
  108. networks:
  109. default:
  110. driver: bridge