Reputation: 1990
Hi my pm2 script in dockerfile(is not working also in my machine)
FROM node:8.11.3
RUN npm install -g pm2
RUN npm install -g esm
ADD . /app
WORKDIR /app
RUN npm install
CMD mkdir -p /logs/ && pm2 start app.js --no-daemon --no-autorestart --node-args="-r esm"
2 issues: sometimes I got errors regarding esm like
syntaxError: Unexpected token import
and somtimes the app is online and than crash but always never running
my app.js: import { getServer } from 'node_modules_folder'
var {app, container} = getServer();
app.listen(3000, async () => {
//get logger by container ....
//print
logger.info(' web-queue-server Server is up!')
})
and the logs is not being fired with pm2
npm start working as it should
Upvotes: 0
Views: 1556
Reputation: 2838
pm2 start app.js
runs in the background. To work with Docker, you have to use pm2-runtime
command which makes the application run in the foreground.
Do note that some or all of the arguments you are passing to pm2
may not work with pm2-runtime
Refer to the documentation here: http://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/
Upvotes: 2