So i’ve been developing this backend on NestJS and Docker using docker-compose also for about 6 months now but never had issues with my docker not listening to my file changes. A few days ago, this started happening and i dont know why.
This is my Dockerfile
FROM node:14-alpine
ENV NODE_ENV development
ENV NODE_OPTIONS=--max_old_space_size=8192
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . .
RUN yarn install
ENTRYPOINT ["yarn", "start:dev"]
And this is my docker-compose file
services:
api:
image: cacao-be
container_name: cacao-be-api
build:
context: .
dockerfile: Dockerfile
ports:
- '3000:3000'
depends_on:
- postgres
volumes:
- ./src:/usr/src/app/src
networks:
- default
links:
- redis
env_file:
- .env
volumes:
db_data:
admin_data:
redis_data:
driver: local
This is my package.json which includes the script to start my proyect
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write "src/**/*.ts" "test/**/*.ts"",
"start": "nest start",
"start:dev": "nest start --watch"
}
HereĀ“s also my tsconfig file
{
"compilerOptions": {
"jsx": "react",
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"resolveJsonModule": true,
"skipLibCheck": true,
},
}
And tsconfig.build.json file
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
I’ve tried running my proyect without docker and it did listen to file changes, but when i run it in docker it stops listening to them. I’ve verifyed and in both approaches it runs in watch mode.
Starting compilation in watch mode...
Also, i’ve entered to my container via cmd, and checked if files were changing as i modified them, and they did (i could prove that my service was well mounted). So inside the container file changes but it doesnt restart the development
I’ve set
command: npm run start:dev
in my docker-compose file, but it didn’t work. Cleaning my docker and restarting it also didnt work.
What i expect is that when i save a file, my docker logs restart and apply changes.
2
Answers
Same issue here with NestJS services in Docker-compose.
Hot reload stops working few days ago.
Dockerfile :
docker-compose.yml file
NestJS scripts
Sorry for being late to the party. Actually it’s due to the TypeScript version. If you upgrade it to
4.9
, then it won’t work anymore. Because in4.9
, they changed how files should be watched, and they’re now using FS events instead of legacy polling. You can read more about it here. So if you want to make it work again, use4.8.4
for now. In yourpackage.json
, change thetypescript
version like so: