I’m experiencing a strange problem, I’m currently using windows 10 and running docker via WSL2, I cloned the repository in my windows file manager and I’m trying to run it in DEV, that is, as soon as I update a file in my local repository this change is reflected within the container, but this is not happening, I have tried different ways.
My dockerfile is like this
FROM node:14-alpine
WORKDIR /src
ADD package.json /src
RUN npm i --silent
ADD . /src
RUN npm run build
CMD npm start
Then I build this image with docker build -t test .
After that I try to upload docker-compose which is as follows.
version: '3'
services:
app:
build: .
command: npm run start:dev
ports:
- 4000:4000
volumes:
- .:/src/
- /src/node_modules
volumes:
nodemodules: {}
And even doing a docker-compose up –build, when I change a file it doesn’t reload automatically.
But when I clone and repeat all the steps correctly in the repository below, the live/hot reload works normally.
https://github.com/ThomasOliver545/nestjs-local-development-docker-compose-hot-reload
These are my dependencies in this project (new project).
"dependencies": {
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0"
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@types/express": "^4.17.13",
"@types/jest": "28.1.8",
"@types/node": "^16.0.0",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "28.1.3",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "28.0.8",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
"typescript": "^4.7.4"
},
What am I doing wrong?
I just need the live/hot reload to work.
Update guys… I just created a VM with ubuntu and ran the same code that was running on my windows and the hot/live reload worked correctly, apparently there is no way to make the container notice changes in the code present in the storage area work from windows into the container.
2
Answers
Move your project to WSL2 filesystem instead of Windows filesystem
Your issue came from the version of typescript and the usage of docker in dev with windows.
In the github link you posted, the version is ^3.7.4 so here 3.10.1.
In your code, the version is "^4.7.4" and so 4.9 can be installed.
Since 4.9 typescript, the watcher checks file changes using the system’s native events for file changes see the release.
This cause an issue with windows and docker mounting volume see issue.
To adjust your code you can downgrade to a previous version or you can keep the last release ( I suggest you this one ). To do so, follow this post