0

I have the docker image from keymetrics/pm2:8-jessie and running my nodejs application well with pm2. I tried to add pm2-logrotate for sizing the log with date. I added the following in my Dockerfile. The module pm2-logrotate can be started but the Target PID is null. Anyone can help please?

FROM keymetrics/pm2:8-jessie

RUN npm install
RUN pm2 install pm2-logrotate
RUN pm2 set pm2-logrotate:retain 90
RUN pm2 set pm2-logrotate:dateFormat YYYY-MM-DD_HH-mm-ss
RUN pm2 set pm2-logrotate:max_size 10M
RUN pm2 set pm2-logrotate:rotateInterval 0 0 * * *
RUN pm2 set pm2-logrotate:rotateModule true
RUN pm2 set pm2-logrotate:workerInterval 10

ENV NODE_ENV=$buildenv
ENV NPM_CONFIG_LOGLEVEL warn

CMD ["sh", "-c", "pm2-runtime start pm2.${NODE_ENV}.config.js"]

pm2 ls

┌──────────────┬────┬─────────┬─────────┬─────┬────────┬─────────┬────────┬─────┬────────────┬──────┬──────────┐
│ App name     │ id │ version │ mode    │ pid │ status │ restart │ uptime │ cpu │ mem        │ user │ watching │
├──────────────┼────┼─────────┼─────────┼─────┼────────┼─────────┼────────┼─────┼────────────┼──────┼──────────┤
│  app_server  │ 1  │ 1.0.0   │ cluster │ 150 │ online │ 1       │ 2h     │ 0%  │ 104.4 MB   │ root │ disabled │
└──────────────┴────┴─────────┴─────────┴─────┴────────┴─────────┴────────┴─────┴────────────┴──────┴──────────┘
Module
┌───────────────┬────┬─────────┬─────┬────────┬─────────┬─────┬───────────┬──────┐
│ Module        │ id │ version │ pid │ status │ restart │ cpu │ memory    │ user │
├───────────────┼────┼─────────┼─────┼────────┼─────────┼─────┼───────────┼──────┤
│ pm2-logrotate │ 2  │ 2.7.0   │ 205 │ online │ 0       │ 0%  │ 44.5 MB   │ root │
└───────────────┴────┴─────────┴─────┴────────┴─────────┴─────┴───────────┴──────┘
Rice
  • 155
  • 3
  • 11

1 Answers1

0

One reason is as pm2 logrotate is not the primary process of the Docker container, but a managed process by pm2, so you can verify this behaviour by stopping main process that is defined pm2.${NODE_ENV}.config.js your container will die no matter if pm2-logrotate is running.

Also, I do not think it should be null, it should be something like

pm2 ls
┌─────┬──────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name             │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼──────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1   │ www              │ default     │ 0.0.0   │ fork    │ 26       │ 13s    │ 0    │ online    │ 0%       │ 40.3mb   │ root     │ disabled │
└─────┴──────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Module
┌────┬───────────────────────────────────────┬────────────────────┬───────┬──────────┬──────┬──────────┬──────────┬──────────┐
│ id │ module                                │ version            │ pid   │ status   │ ↺    │ cpu      │ mem      │ user     │
├────┼───────────────────────────────────────┼────────────────────┼───────┼──────────┼──────┼──────────┼──────────┼──────────┤
│ 0  │ pm2-logrotate                         │ 2.7.0              │ 17    │ online   │ 0    │ 0.5%     │ 43.1mb   │ root     │
└────┴───────────────────────────────────────┴────────────────────┴───────┴──────────┴──────┴──────────┴──────────┴──────────┘

Also will suggest to use the alpine base image as the above image seem very heavy, the below image is 150MB while the above image is arround 1GB.

FROM node:alpine
RUN npm install pm2 -g

RUN npm install
RUN pm2 install pm2-logrotate
RUN pm2 set pm2-logrotate:retain 90
RUN pm2 set pm2-logrotate:dateFormat YYYY-MM-DD_HH-mm-ss
RUN pm2 set pm2-logrotate:max_size 10M
RUN pm2 set pm2-logrotate:rotateInterval 0 0 * * *
RUN pm2 set pm2-logrotate:rotateModule true
RUN pm2 set pm2-logrotate:workerInterval 10

ENV NODE_ENV=$buildenv
ENV NPM_CONFIG_LOGLEVEL warn
WORKDIR /app
COPY . /app

CMD ["sh", "-c", "pm2-runtime start confi"]
Adiii
  • 54,482
  • 7
  • 145
  • 148