Nodemon: Nodemon not restarting in docker

Created on 12 Nov 2018  Â·  14Comments  Â·  Source: remy/nodemon

  • nodemon -v: 1.18.6 (latest)
  • node -v: 10.13
  • Operating system/terminal environment:

    • Docker version 18.06.1-ce, build e68fc7a

    • docker-compose version 1.22.0, build f46880f

  • Command you ran:

docker-compose.yml:

version: '3.1'

services:
  node:
    image: node:10
    working_dir: /usr/local/src/
    volumes:
      - .:/usr/local/src/
    environment:
      - NODE_ENV=development
    command: bash -c "nodemon --watch src --exec 'node src/server.js'"

Run: docker-compose up

Expected behaviour

Should restart when I change a file in src/

Actual behaviour

Does not restart

Steps to reproduce

  1. mkdir -p test/src && touch test/docker-compose.yml && touch test/src/server.js
  2. Copy above contents into docker-compose.yml
  3. Run cd test && docker-compose up
  4. Try changing something in server.js and observe

Known Solution

If I add the -L flag, everything works great! Something got killed in the latest version (https://github.com/docker/labs/issues/378)

Most helpful comment

@remy this appears to be a symptom of a nodemon change. After upgrading, we had to follow https://github.com/remy/nodemon#application-isnt-restarting to make it work in docker.

All 14 comments

Is this a nodemon issue or docker?

@remy this appears to be a symptom of a nodemon change. After upgrading, we had to follow https://github.com/remy/nodemon#application-isnt-restarting to make it work in docker.

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@remy any thoughts on this?

Missed your comment. Are you able to replicate intended behaviour with a previous version of nodemon (with the latest docker)? I've not got any experience with docker, so I don't fully understand the internals of what happens with docker.

I've managed to spend more than a day debugging this problem so let me help provide my learnings.

For some context, I have an extra step in my build process. I have tsc --watch handling code transpiling and bundling. Previously with an earlier version of nodemon I had this system running locally.

Through quite a bit of investigation I started to notice that while nodemon was not restarting, the updated build files were successfully being picked up within the container itself.

A further insight revealed that if I manually changed a file from within the container, nodemon restarted as expected.

With this I then attempted to just run my watch system from the container itself and voila, I had nodemon restarted following local changes again!

To be perfectly honest I don't know exactly why changing the execution context of the file changes matters.

I attempted to revert the commits of the last few versions of nodemon to see if that fixed the original problem and still saw no change in behavior.

My hunch is that a dependency of nodemon that handles the fs watch has broken the existing functionality. Somehow in the execution path of mac os file change -> container volume symlink change is not being picked up by nodemon.

Considering I don't know enough about nodemon's internals and I have a working environment again, i've not looked further into trying to figure out what dependency might be to blame here.

Key question (that I'll be adding to my issue template): what docker image are you using?

I think this is a dupe of #1484 and I think you're using Alpine, so it'll be fixed once I push a fix…

Live fix in [email protected] (core change in pstree.remy…again).

I was fix this problem @leifdejong it work! just change some in docker-compose.yml

command nodemon index.js
command nodemon -L index.js

This worked for me (adding inotify-tools to my Dockerfile): https://stackoverflow.com/a/46804953/2397773

It also fixed the same issue I had with webpack-dev-server not reloading.

I was fix this problem @leifdejong it work! just change some in docker-compose.yml

command nodemon index.js
command nodemon -L index.js

Thank you very much this worked for me

I was fix this problem @leifdejong it work! just change some in docker-compose.yml

command nodemon index.js
command nodemon -L index.js

Thanks working for me.

I was fix this problem @leifdejong it work! just change some in docker-compose.yml

command nodemon index.js
command nodemon -L index.js

thanks u.

For me even using the -L flag does not work. I am using a node image as the base image and when installing nodemon inside the container it gives the following warning.

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/nodemon/node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

I think chokidar and fsevents are related to this nodemon restarting. any suggestions how to fix ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

endquote picture endquote  Â·  4Comments

remy picture remy  Â·  5Comments

giacomorebonato picture giacomorebonato  Â·  5Comments

piton13 picture piton13  Â·  3Comments

maotora picture maotora  Â·  4Comments