Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodemon not restarting when files change in Docker #1802

Closed
cullylarson opened this issue Nov 25, 2020 · 33 comments
Closed

Nodemon not restarting when files change in Docker #1802

cullylarson opened this issue Nov 25, 2020 · 33 comments
Labels
docker stale no activity for 2 weeks

Comments

@cullylarson
Copy link

cullylarson commented Nov 25, 2020

  • 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.

@purplehat7
Copy link

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

@tristoncarter34
Copy link

doesnt work for me either

@cullylarson
Copy link
Author

cullylarson commented Nov 26, 2020

@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
Copy link
Author

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

@tristoncarter34
Copy link

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.

@cullylarson
Copy link
Author

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

@tristoncarter34
Copy link

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

@cullylarson
Copy link
Author

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

@cullylarson
Copy link
Author

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

@jsinterface
Copy link

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.

@cullylarson
Copy link
Author

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

@github-actions
Copy link

github-actions bot commented Jul 9, 2021

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 github-actions bot added the stale no activity for 2 weeks label Jul 9, 2021
@cullylarson
Copy link
Author

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

@github-actions github-actions bot removed the stale no activity for 2 weeks label Jul 9, 2021
@remy
Copy link
Owner

remy commented Jul 9, 2021

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

@remy remy added the docker label Jul 9, 2021
@cullylarson
Copy link
Author

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

@paxperscientiam
Copy link

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

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

@giancarlosisasi
Copy link

😢

giancarlosisasi added a commit to giancarlosisasi/elearning-clone-nodejs that referenced this issue Sep 20, 2021
…ntainer

Nodemon will not reestar the process without this flag :(
remy/nodemon#1802
@luongjames8
Copy link

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

@ugnmura
Copy link

ugnmura commented Nov 19, 2021

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

@goshander
Copy link

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

@ugnmura
Copy link

ugnmura commented Nov 20, 2021

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

@mikeclagg
Copy link

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

@ugnmura
Copy link

ugnmura commented Dec 2, 2021

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

@shaunakv1
Copy link

--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

@github-actions
Copy link

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 github-actions bot added stale no activity for 2 weeks and removed stale no activity for 2 weeks labels Jun 28, 2022
@github-actions
Copy link

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 github-actions bot added the stale no activity for 2 weeks label Jul 12, 2022
@github-actions
Copy link

Automatically closing this issue due to lack of activity

@manutorres
Copy link

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

@ahmednawaz10p
Copy link

nodemon -L worked for me as well

@junjielyu13
Copy link

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

@SirPeace
Copy link

SirPeace commented Nov 2, 2023

Super stupid solution that worked for me:

Try to use WORKDIR /var/www in your Dockerfile (or experiment with smth else, don't forget to edit volume paths as well) instead of well known /app.

I still don't get how it may affect the result, but I couldn't manage to make nodemon restart with WORKDIR /app

@mmiglioranza22
Copy link

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

Doing this fixed the issue perfectly, thanks!

@parthmern
Copy link

-L worked for me thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker stale no activity for 2 weeks
Projects
None yet
Development

No branches or pull requests