pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

Docker and commander js

Open sm2017 opened this issue 2 years ago • 4 comments

What's going wrong?

I am using CMD ["pm2-runtime", "start", "ecosystem.config.js", "--env", "production"] in my Dockerfile to run my applications in the docker via pm2 Outside of docker pm2 start ecosystem.config.js --env production works well

but in the docker, When I run pm2 log 0 I have error like error: unknown command 'start' When I using CMD ["pm2-runtime", "ecosystem.config.js", "--env", "production"] the error is error: unknown command 'ecosystem.config.js'

How could we reproduce this issue?

app.js

const { program } = require('commander');

program
  .command('clone <source> [destination]')
  .description('clone a repository into a newly created directory')
  .action((source, destination) => {
    console.log('clone command called');
  });

ecosystem.config.js

module.exports = [{
  script: 'app.js',
  name: 'app',
  args: 'clone foo bar',
  instances: 2
}

Dockerfile

FROM node:16 
RUN npm install pm2 -g
CMD ["pm2-runtime", "ecosystem.config.js"]

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Tue Nov 30 2021 13:15:01 GMT+0000 (Coordinated Universal Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.1.2
node version         : 16.13.0
node path            : not found
argv                 : /usr/local/bin/node,/usr/local/bin/pm2-runtime,start,ecosystem.config.js,--env,production
argv0                : node
user                 : undefined
uid                  : 0
gid                  : 0
uptime               : 0min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.1.2
node version         : 16.13.0
node path            : not found
argv                 : /usr/local/bin/node,/usr/local/bin/pm2,report
argv0                : node
user                 : undefined
uid                  : 0
gid                  : 0
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz
cpus nb              : 4
freemem              : 3189035008
totalmem             : 9893634048
home                 : /root
===============================================================================

sm2017 avatar Nov 30 '21 13:11 sm2017

I log process.argv its totally wrong

[
'/usr/local/bin/node',
'/usr/local/lib/node_modules/pm2/lib/ProcessContainer.js',
'start',
'ecosystem.config.js',
 '--env',
 'production',
 'clone'
]

sm2017 avatar Nov 30 '21 14:11 sm2017

PM2的问题,请参考如下命令flush即可。另外PM2会往process.env又注入一个env,结果就是process.env.env="[object Object]",我已经降回4的版本了 CMD node_modules/pm2/bin/pm2 flush && node_modules/pm2/bin/pm2-docker start ecosystem.config.js

lanxuebao avatar Dec 06 '21 10:12 lanxuebao

same problem here, any updates on this thread?

simonzg avatar Oct 12 '22 23:10 simonzg

I have the same issue. Can anyone help?

  "dependencies": {
    "commander": "^12.0.0",
    "pm2": "^5.3.1"
  }

eskylake avatar Apr 09 '24 13:04 eskylake