Trying to start pm2-runtime with 3 instances for a MEAN application

1.1k Views Asked by At

I am trying to start an existing MEAN stack app in a Docker container by using the following Docker command:

CMD ["pm2-runtime", "-i", "3", "npm", "--", "run-script", "start:prod"]

That command does start 3 PM2 instances, however it seems that the npm portion is not running the run-script part and it hangs with the following message in each instance:

Usage: npm <command>
where <command> is one of:
    access, adduser, bin, bugs, c, cache, completion, config,
    ddp, dedupe, deprecate, dist-tag, docs, edit, explore, get,
    help, help-search, i, init, install, install-test, it, link,
    list, ln, login, logout, ls, outdated, owner, pack, ping,
    prefix, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, tag, team, test, tst, un, uninstall,

If I remove the "-i", "3" portion, it correctly starts 1 instance of the app in "fork" mode.

Anyone know what would be the correct syntax for starting 3 instances, considering its using NPM with a run-script?

Thank you

2

There are 2 best solutions below

1
On

Add "start" to CMD line

CMD ["pm2-runtime", "start", "-i", "3", "npm", "--", "run-script", "start:prod"]
1
On

-- is a bash-specific feature which signifies the end of command line options.

You are however not running bash, but calling the pm2-runtime binary and passing the arguments to it.

Thus it's essentially equivalent to calling npm with -- as the command.

I think that -- can be removed and it should work.