I am trying to run pm2-runtime npm start
as a docker CMD.
When I go into the container and run pm2-runtime npm start
everything is ok but I want to automate it.
I have tried:
CMD ["pm2-runtime", "npm start"]
CMD ["pm2-runtime", "npm", "start"]
CMD ["pm2-runtime", "'npm start'"]
The above commands don't work and all-cause this kind of error
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
Seams like an easy issue and pm2-runtime is capable of npm start, so what am I doing wrong?
First thing, npm start
and pm2-runtime
both run application in the foreground, then any special reason for running npm start
with pm2-runtime?
As you can wrapped into a proper Node.js production environment with process.yml instead of npm start
.
process.yml
apps:
- script : myapp.js
name : 'myapp'
error_file : './logs/myapp.log'
out_file : './logs/myapp.log'
you can also start multiple process in YML config file.
CMD ["pm2-runtime", "process.yml"]
Now come to your problem so you can just change your CMD to below and it should work.
CMD pm2-runtime 'npm start'
or
CMD ["/bin/sh", "-c", "pm2-runtime 'npm start'"]
For complete demo app, you can check nodejs-docker-pm2-runtime