Docker Volume Link Windows (Nodemon) - The Ultimate Docker Course

Hello to everybody. I’m doing the “The Ultimate Docker Course” and I’m on a Windows Machine.

The following 2 lessons have a nodemon problem that will not update the app after a modify is made:

11- Sharing the Source Code with a Container
11- Publishing Changes

To fix the problem and allow the react app to update after a change is made, we need to go in packages.js in the following section, at the start row (here is the original config of the “Publishing Changes” lesson)

“scripts”: {
“db:up”: “migrate-mongo up”,
"start": “nodemon --ignore ‘./tests’ index.js”,
“test”: “jest --watchAll --colors”
},

And we need to add after nodemon -L

“scripts”: {
“db:up”: “migrate-mongo up”,
“start”: “nodemon -L --ignore ‘./tests’ index.js”,
“test”: “jest --watchAll --colors”
},

Because nodemone inside a docker container requires the legacy flag.

Hope it can help someone, and if need more info here is the source: Nodemon inside a docker container requires the use of the legacy watch flag -L · Issue #378 · docker/labs · GitHub

Raul88, there is a MS page I came across I think about sharing volumes but you really want to go native with WSL2. Have you enabled WSL2 and installed a Ubuntu distro on WSL2? You ought to aim for coding directly into ubuntu.
If not already:
Install WSL on Windows 10 | Microsoft Docs
I use the windows terminal mostly rather than the Ubuntu specific terminal. You can open up a session on the Windows terminal from the drop down menu once you have wsl installed. Get Windows Terminal - Microsoft Store en-AU
I set up aliases to cd and cp from /mnt/c drive to Ubuntu root directory. I created a .sh file in the etc/profile.d .
ubhub@DESKTOP-PRO:/etc$ cat ./profile.d/myenv-var.sh
export DC=/mnt/c/users/brian/DockerImages
export DV=/app/vidly
The problem I still haven’t solved is to sudo code from the terminal with root privileges because all of Mosh’s files I’ve copied in to the Linux directory are privileged. So I’ve been making do with sudo nano for the time being.

Thanks for the tips. I already had WSL2 enabled, it’s something needed to start this course if working on a Windows pc.

The nodemon not refreshing happens when inside a docker container, at least is what the Github source I posted says. Including the legacy -L just solved the issue for me.

Thanks Raul88. Good tip. Haven’t had any issues with nodemon since installing node on WSL, but will make a note of that change in script.

@Raul88 Good catch. The problem here is not with Docker, but how WSL works under the hood. Linux containers only receive inotify events(file change events) if the changes are made in the Linux file system. So any tool that watches files for changes like nodemon, jest, create-react-app will not work if the file changes are made on the Windows file system. You can read more about it here. The only way to go around this issue as of now is to store your source files in the Linux file system. It’s not ideal, but it is what it is. Storing the source code in the Linux file system should also give you a performance increase when using Docker to move files. The WSL team is aware of this issue and are working to change this behaviour in the future.

1 Like