S
S
Sergey2018-07-22 10:46:54
macOS
Sergey, 2018-07-22 10:46:54

How to properly run nodemon from docker without CPU load?

Hello.
There are files:

Dockerfile
FROM node:alpine
RUN yarn global add nodemon

docker-compose.yml
version: '3'
services:
  server_node:
    build: ./app/
    volumes:
      - "./app:/app"
    ports: 
      - "9000:3000"
    command: "nodemon --legacy-watch --polling-interval 4000 /app/bin/server.node.js"


A simple container that runs nodemon and watches /app/bin/server.node.js (hello world expressJS) for changes. Everything works, but the problem is that after starting nodemon, the CPU load of the com.docker.hyperkit process grows (at least) by 150%.
If nodemon is replaced with a regular node: command: "node /app/bin/server.node.js", then no file tracking occurs and no CPU load occurs.
Many people had this problem, judging by the messages in github issues, etc. in 2016-2017. The solution was to reduce nodemon's polling interval and use legacy-watch, which is advised even in the official documentation. In my case, unfortunately, it did not help.
I also noticed that if you ignore the load and change server.node.js, then nodemon in docker restarts not once, as it should, but 5-20 times with almost no delay (the number of restarts is not always the same). There is a feeling that nodemon constantly receives notifications that the file has changed, checks which part has changed, but does not find differences and falls asleep.
Has anyone experienced this kind of file tracking behavior in docker? Is there any rational solution to this phenomenon?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Yandimirkin, 2018-07-25
@vlaad360

After some time tormenting with nodemon, we took pm2-dev and it became much better pm2.keymetrics.io/docs/usage/pm2-development

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question