'pm2 command not working from a docker image
I have a pm2 command in my docker file which should run inside container when the container starts:
CMD ["pm2", "start", "ecosystem.local.json"]
CMD ["pm2", "logs"]
Expected output: showing logs of my process
Actual output: no logs but container is running.
Seems like the first command doesnt start the process because when i go inside the container and run pm2 list
manually then i dont see any process running.
But when i run the same above commands from inside the container manually:
pm2 start ecosystem.local.json
pm2 list
pm2 logs
then i can see my process running and its logs.
So why the command CMD ["pm2", "start", "ecosystem.local.json"]
doesnt run automatically from the docker file/image?
P.S. I also used pm2-runtime
from https://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/ but no success.
Solution 1:[1]
As pointed out in comment, my container was getting started and immediately exiting after that. I was using pm2
and switching to pm2-runtime
did the work.
Not working:
"start-server": "export NODE_ENV=production && cd server && ./node_modules/.bin/pm2 start index.js",
Working:
"start-server": "export NODE_ENV=production && cd server && ./node_modules/.bin/pm2-runtime start index.js",
From Dockerfile-
CMD ["yarn", "start-server"]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Varun Kumar |