我试图在我的应用程序上安装PM2,它在localhost上运行良好。但是,当我将应用程序移至docker容器并尝试在Linux机器上运行时,会发生问题。
我正在运行命令npm run production,该命令执行以下代码:
pm2 start ecosystem.config.js --env production --no-autorestart
此后,在命令行上,我看到了PM2的启动方式并在所有可用内核上启动了我的应用程序。
app | [PM2] PM2 Successfully daemonized
app | [PM2][WARN] Applications App not running, starting...
app | [PM2] App [App] launched (2 instances)
app | ┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
app | │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
app | ├─────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
app | │ 0 │ App │ default │ 1.0.0 │ cluster │ 36 │ 0s │ 0 │ online │ 0% │ 38.0mb │ root │ disabled │
app | │ 1 │ App │ default │ 1.0.0 │ cluster │ 43 │ 0s │ 0 │ online │ 0% │ 25.0mb │ root │ disabled │
app | └─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
然后它返回一条消息:
app exited with code 0
整个过程一次又一次地陷入困境... 我尝试在“ fork”上的“ cluster_mode”上运行它,我尝试使用--no-autorestart运行它,但它仍然不断重启。
我真的不知道我在做什么错?
@@ EDIT,添加了ecosystem.config.js
module.exports = {
apps : [{
name: 'App',
script: './build/server/index.js',
// Options reference: https://pm2.keymetrics.io/docs/usage/application-declaration/
exec_mode: 'cluster_mode',
args: 'none',
instances: os.cpus().length,
autorestart: false,
watch: false,
// max_memory_restart: '3G',
env: {
NODE_ENV:'development',
},
env_production: {
NODE_ENV:'production',
}
}],
deploy : {
production : {
user : 'szygendab',
host : '212.83.163.1',
ref : 'origin/master',
repo : 'git@github.com:repo.git',
path : '/var/www/production',
'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production'
}
}
};
答案 0 :(得分:0)
更新
我找到了解决方案。基本上,docker上的应用程序不应从pm2开始运行,而应从pm2-runtime开始运行。这就是为什么它在localhost而不是在docker映像内工作的原因。据我了解,docker完成了一个任务并关闭了它,此后它继续接收另一个启动任务,并正在循环启动该应用程序。
相反,pm2 start...。我将测试实例的方法切换为pm2-runtime start ...,它很有帮助。
答案 1 :(得分:0)