fixed:镜像健康检查问题

This commit is contained in:
djteang 2025-09-21 01:23:06 +08:00
parent 167d328116
commit f3138e9681
1 changed files with 9 additions and 8 deletions

View File

@ -89,13 +89,7 @@ RUN corepack enable && corepack prepare pnpm@latest --activate && \
# 清理安装缓存减小镜像大小 # 清理安装缓存减小镜像大小
pnpm store prune pnpm store prune
# 切回非特权用户 # 创建健康检查脚本在切换用户之前以root权限创建
USER nextjs
# 暴露HTTP和WebSocket端口
EXPOSE 3000 3001
# 创建健康检查脚本
RUN echo '#!/usr/bin/env node\n\ RUN echo '#!/usr/bin/env node\n\
const http = require("http");\n\ const http = require("http");\n\
const options = {\n\ const options = {\n\
@ -129,7 +123,14 @@ req.on("timeout", () => {\n\
\n\ \n\
req.setTimeout(5000);\n\ req.setTimeout(5000);\n\
req.end();' > /app/healthcheck.js && \ req.end();' > /app/healthcheck.js && \
chmod +x /app/healthcheck.js chmod +x /app/healthcheck.js && \
chown nextjs:nodejs /app/healthcheck.js
# 切回非特权用户
USER nextjs
# 暴露HTTP和WebSocket端口
EXPOSE 3000 3001
# 添加健康检查 # 添加健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \