作为docker CMD运行PM2-runtime npm start的问题

时间:2020-06-10 22:16:14

标签: docker npm devops pm2

我正在尝试将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,那么我在做什么错了?

1 个答案:

答案 0 :(得分:0)

第一件事,npm startpm2-runtime都在前台运行应用程序,然后出于特殊原因在pm2-runtime中运行npm start

您可以使用process.yml而不是npm start来封装到proper Node.js production environment中。

process.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