我的 docker 文件中有一个 pm2 命令,当容器启动时,该命令应该在容器内运行:
CMD ["pm2", "start", "ecosystem.local.json"]
CMD ["pm2", "logs"]
预期输出:显示我的流程日志
实际输出:没有日志,但容器正在运行。
似乎第一个命令没有启动该进程,因为当我进入容器并手动运行
pm2 list
时,我看不到任何进程正在运行。
但是当我从容器内部手动运行上述相同命令时:
pm2 start ecosystem.local.json
pm2 list
pm2 logs
然后我可以看到我的进程正在运行及其日志。
那么为什么命令
CMD ["pm2", "start", "ecosystem.local.json"]
不会从 docker 文件/镜像自动运行?
附注我还使用了
https://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/中的
pm2-runtime
但没有成功。
正如评论中所指出的,我的容器正在启动,然后立即退出。我正在使用
pm2
,然后切换到 pm2-runtime
完成了工作。
不工作:
"start-server": "export NODE_ENV=production && cd server && ./node_modules/.bin/pm2 start index.js",
工作:
"start-server": "export NODE_ENV=production && cd server && ./node_modules/.bin/pm2-runtime start index.js",
来自 Dockerfile-
CMD ["yarn", "start-server"]
瓦伦·库马尔是对的。 对我来说添加
--attach
可以工作 "scripts": {
"start": "pm2 start ecosystem.config.js --attach --watch",
},