我正在尝试运行 pm2-runtime npm start
作为docker CMD.当我进入容器并运行 pm2-runtime npm start
一切都很好,但我想把它自动化。
我已经试过了。
CMD ["pm2-runtime", "npm start"]
CMD ["pm2-runtime", "npm", "start"]
CMD ["pm2-runtime", "'npm start'"]
上面的命令没有用,而且都会导致这样的错误。Usage: npm <command>
where <command> is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, fund, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
看起来是个很简单的问题,而且 pm2-runtime 也能启动 npm,那么我到底做错了什么?
第一件事。npm start
和 pm2-runtime
都是在前台运行的应用程序,那么任何特殊的原因,运行的 npm start
与 pm2-runtime?
就像你可以把它包装成一个 适当的Node.js生产环境 用process.yml代替 npm start
.
流程.yml
apps:
- script : myapp.js
name : 'myapp'
error_file : './logs/myapp.log'
out_file : './logs/myapp.log'
你也可以在YML配置文件中启动多个进程。
CMD ["pm2-runtime", "process.yml"]
现在来看看你的问题,所以你可以把你的CMD改成下面的,它应该可以工作。
CMD pm2-runtime 'npm start'
或
CMD ["/bin/sh", "-c", "pm2-runtime 'npm start'"]
完整的演示程序,你可以查看 nodejs-docker-pm2-runtime。