Running node.js apps with forever on docker containers

As part of dockerizing our micro services I came across an issue where our node.js app would go nuts and lock all the CPU cycles of the docker host:

cdos_helionode_1    190.07%             172.7 MB/6.25 GB    2.76%               2.123 kB/1.852 kB

After doing some digging and trying to isolate the problem I found that the CPU spike was being caused when the forever watch was turned on. That was odd since I never came across that problem while running the app with forever on my mac with all the files being watched. Doing some more digging I found existing tickets documenting the issue 1 2 with the watch flag.

To solve the problem I had to do two things.

First Update forever to the latest version (0.15.1)

Second Update .foreverignore file


I tried a few different patterns:

  • /.git
  • /.git/
  • **/.git/**
  • .git

But the only one that worked was .directoryName/


The CPU spikes seemed to be caused by the fact that forever was trying to watch all the files in the directory, including the whole git tree, all the node_modules and the webstorm settings files. Why the issue only came to surface when running the app in a linux container and not on the mac I’m not sure. But it is clear that the latest update made to forever addressed the issue as long as the .foreverignore uses the correct syntax.