nodemon icon indicating copy to clipboard operation
nodemon copied to clipboard

Nodemon not restarting when files change in Docker

Open cullylarson opened this issue 3 years ago • 26 comments

  • nodemon -v: 2.0.6
  • node -v: v12.18.1
  • Operating system/terminal environment: MacOS
  • Using Docker? What image: Yes, node:12. Running Docker version 19.03.13, build 4484c46d9d.
  • Command you ran: nodemon --watch server server/app.js

Expected behaviour

The app is running inside a Docker container, with the project folder mounted as a volume. When a file is changed from the host machine, nodemon should restart the app.

Actual behaviour

Nodemon doesn't seem to notice the file change and doesn't restart the app. cating the file or checking the timestamp inside the Docker container, the file is changed in the container as well.

NOTE: Using the -L flag does work. Nodemon will respond to changes with -L.

Steps to reproduce

I created a repo that reproduces the issue: https://github.com/cullylarson/nodemon-watch-issue

The docker-compose file mounts the volume as read-only. I've tried it mounting as writable, but get the same result.

cullylarson avatar Nov 25 '20 21:11 cullylarson

Have you tried passing the -L flag to nodemon? Do nodemon --help options for more info.

purplehat7 avatar Nov 26 '20 04:11 purplehat7

doesnt work for me either

tristoncarter34 avatar Nov 26 '20 04:11 tristoncarter34

@acannon828 -L works. I actually mention it in the repo. I'll update the issue to include it as well. That's what I've been using since noticing this problem. Though it doesn't seem like a great long-term solution, especially if this is broadly affecting nodemon in Docker (+ MacOS?).

cullylarson avatar Nov 26 '20 05:11 cullylarson

I think chokidar has made some recent updates to fix Docker issues. Maybe this is just a matter of updating the chokidar dep?

cullylarson avatar Nov 26 '20 05:11 cullylarson

so could you help me with this , I'm new to express and what is occurring that the latest version isn't restarting or refreshing the browser.

tristoncarter34 avatar Nov 26 '20 05:11 tristoncarter34

@tristoncarter34 This may not be the same issue. Have you tried posting your question on Stackoverflow?

cullylarson avatar Nov 26 '20 06:11 cullylarson

actually no i thought maybe you guys can give some insight on my issue that only started this few minutes ago

tristoncarter34 avatar Nov 26 '20 06:11 tristoncarter34

FYI, I tried cloning nodemon and updating chokidar to 3.4.2 and it doesn't seem to have fixed the issue.

cullylarson avatar Dec 03 '20 19:12 cullylarson

I reproduced the same problem with chokidar alone, so this might just be a chokidar issue. I posted an issue there: https://github.com/paulmillr/chokidar/issues/1051.

cullylarson avatar Dec 03 '20 20:12 cullylarson

I have this issue when running nodemon in a fuse mount, I don't know how these file change events look like and what handles them, might this be a similar or the same chokidar issue? Or should I open a separate one about fuse mounts? I think legacyWatch solves it but I don't wanna do that.

bpstrngr avatar Dec 13 '20 20:12 bpstrngr

@bpstrngr I don't know if it's the same. I have gRPC FUSE turned off.

cullylarson avatar Dec 13 '20 20:12 cullylarson

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

github-actions[bot] avatar Jul 09 '21 09:07 github-actions[bot]

It is still an issue. It just seems to be an issue with chokidar.

cullylarson avatar Jul 09 '21 18:07 cullylarson

Might be worth creating a completely pared back test that only uses chokidar in docker to test for changes?

remy avatar Jul 09 '21 19:07 remy

@remy I posted an issue in the chokidar repo a while back, with an example of how to reproduce using only chokidar: https://github.com/paulmillr/chokidar/issues/1051.

cullylarson avatar Jul 09 '21 20:07 cullylarson

NOTE: Using the -L flag does work. Nodemon will respond to changes with -L.

Thank you, @cullylarson . Solved it for me too.

paxperscientiam avatar Sep 17 '21 00:09 paxperscientiam

😢

GiancarlosIO avatar Sep 19 '21 23:09 GiancarlosIO

I am having this same issue, and the -L flag makes no impact.

luongjames8 avatar Oct 13 '21 16:10 luongjames8

Same here -L or --legacy-watch does not work.

SushiWaUmai avatar Nov 19 '21 00:11 SushiWaUmai

Same here -L or --legacy-watch does not work.

Maybe I can help you, please write your version of docker, node, nodemon and OS type

goshander avatar Nov 19 '21 03:11 goshander

I have:

docker 20.10.10
docker compose 2.1.1
node 16.13.0
nodemon 2.0.15
Windows

Same here -L or --legacy-watch does not work.

Maybe I can help you, please write your version of docker, node, nodemon and OS type

I have:

docker 20.10.10
docker compose 2.1.1
node 16.13.0
nodemon 2.0.15
Windows

SushiWaUmai avatar Nov 20 '21 17:11 SushiWaUmai

I have the same problem on windows, on my mac, it runs fine.

docker 20.10.10 docker compose 2.1.1 node 16.13.0 nodemon 2.0.15 Windows

I mount the repo into the docker container, it spins up and works with requests but never triggers a restart when files in scope are changed. The Dockerfile and the exact same setup works on Mac and Ubuntu desktops

mikeclagg avatar Dec 01 '21 22:12 mikeclagg

I solved my problem by putting the src directory into a volume.

SushiWaUmai avatar Dec 02 '21 07:12 SushiWaUmai

--legacy-watch works for me. However it doesn't respect the directory names to restrict the watch to. This is a lot of overhead in projects where we split server and worker code and need to manage the lifecycle separately.

Should watching the specific directories be working using --legacy-watch?

Here's my docker file:

version: '3.4'

x-service-defaults:
  &service-defaults
  image: dav/gdal:latest
  build:
    context: .
    dockerfile: ./Dockerfile
  environment:
    NODE_ENV: production
    REDIS_HOST: redis
  volumes:
    - ./src:/dav/src
    - ./data:/data

services:
  worker:
    <<: *service-defaults
    command:
      [
        "nodemon",
        "--legacy-watch",
        "jobs/workers",
        "src/jobs/workers/index.js"
      ]
  web:
    <<: *service-defaults
    ports:
      - 5000:5000
      - 9229:9229
    command:
      [
        "nodemon",
        "--inspect=0.0.0.0:9229",
        "--legacy-watch",
        "/dav/src/app.js",
        "-e",
        "html,css,js,sql"
      ]
  redis:
    image: redis:6.0.16-alpine
    ports:
      - 6379:6379

shaunakv1 avatar Mar 21 '22 15:03 shaunakv1

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

github-actions[bot] avatar Jun 28 '22 10:06 github-actions[bot]

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

github-actions[bot] avatar Jul 12 '22 11:07 github-actions[bot]

Automatically closing this issue due to lack of activity

github-actions[bot] avatar Aug 11 '22 12:08 github-actions[bot]

nodemon -L did the trick here as well. Thanks.

manutorres avatar Oct 28 '22 00:10 manutorres

nodemon -L worked for me as well

ahmednawaz10p avatar Jan 17 '23 09:01 ahmednawaz10p

woaw thank you so much, nodemon --legacy-watch work on me

junjielyu13 avatar Feb 03 '23 15:02 junjielyu13