n8n2 / Dockerfile
stnh70's picture
Update Dockerfile
8bfe0bc verified
# 使用する Node.js のバージョンを指定
FROM node:24.8.0
# ポートの公開
EXPOSE 7860
# 环境变量的设置
ENV N8N_PORT=7860
ENV WEBHOOK_URL=https://stnh70-n8n2.hf.space/
ENV VUE_APP_URL_BASE_API=https://stnh70-n8n2.hf.space/
# n8n のグローバルインストール
RUN npm install n8n -g
# 创建启动脚本目录
RUN mkdir -p /app
# 创建启动脚本
COPY <<EOF /app/start-with-heartbeat.js
const { spawn } = require('child_process');
// Periodic heartbeat to confirm event loop activity (can be removed later)
let hbCount = 0;
setInterval(()=>{
hbCount++;
if (hbCount % 6 === 0) { // every 60s if interval is 10s
console.log('[diagnostic] heartbeat 60s elapsed, process alive');
}
}, 10_000).unref();
// 启动 n8n
console.log('[diagnostic] Starting n8n with heartbeat monitoring...');
const n8nProcess = spawn('n8n', ['start'], {
stdio: 'inherit',
env: process.env
});
// 处理进程退出
n8nProcess.on('exit', (code, signal) => {
console.log(\`[diagnostic] n8n process exited with code \${code}, signal \${signal}\`);
process.exit(code);
});
// 处理脚本退出时的信号
process.on('SIGTERM', () => {
console.log('[diagnostic] Received SIGTERM, shutting down gracefully...');
n8nProcess.kill('SIGTERM');
});
process.on('SIGINT', () => {
console.log('[diagnostic] Received SIGINT, shutting down gracefully...');
n8nProcess.kill('SIGINT');
});
EOF
# 使用带心跳监控的启动脚本
CMD ["node", "/app/start-with-heartbeat.js"]