I was putting together a video on how to set up compose watch for a MERN app and found that “node --watch” stops picking up changes when run via docker compose watch after the first one. I’m able to resolve by bringing in nodemon, but considering this is built into node, that would be my preferred approach. Seems like this is some kind of compose watch bug.
The link below goes directly to the part of the video where I demonstrate this issue.
I wouldn’t be surprised, but I couldn’t reproduce it with the example from the compose watch documentation that you mentioned in your video too. I used macOS. I guess you are using Docker Desktop for Linux. That could be a difference or or it is indeed related to node. Is your code available somewhere so I could try it?
Forgive me, If I am all wrong. I haven’t seen the video, but I have a hunch about what might be the situation and the cause
If a container uses a file watch for a folder that is bound from the host into the container, then it can’t work with Docker Desktop if files are edited on the host.
Usually file notification frameworks depend on inotify on Linux, which itself relies on kernel filesystem. If files are edited on the host, the host kernel will register the filesystem events. Since Docker Desktop always runs the docker engine in a utility vm, the container will use the kernel of utiltiy vm, and as such will not be able to register on filesytem events of the host.
It should work with docker-ce though.
Update: my bad, I just looked into the example projects. It’s the native Docker Desktop watch feature of Docker Compose. Forget what I wrote, of course this feature should work.
Thank you for the source code. After I replaced nodemon with node --watch I got the same result with the issue you had. Then I tried without Docker and it worked. So I tried with Docker again and the first sync changes the owner of the file and also the inode. Meaning that the file you were watching is not there anymore. It is a new file with the same name.
To be honest I didn’t use compose watch before, so I’m not 100 percent sure how it works, but since the file changes that seems working, but node --watch and nodemon was probably implemented differently so nodemon see the changes but node doesn’t. When I tried with the example from the docker documentation, that used yard dev not specifying the file.