'NestJs doesn't work in "watch" mode inside Docker
I am trying to use NestJs inside Docker. For the first run 'docker compose up --build' it works good, all changes in files force application to rebuild. But if I stop docker with 'docker compose down' and then 'up' it again - application stops to react on any changes. Sometimes, it gets stuck on the command 'nest start --watch'. I tried almost everything, but only purging all docker data helps to make it work again until another 'down'. If I remove volumes, it works, but it doesn't see any file's changes. What should I do to make it work?
Dockerfile:
FROM node:14-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
CMD ["node", "dist/main"]
docker-compose.yml:
version: '3.7'
services:
main:
build: .
command: npm run start:dev
volumes:
- .:/usr/src/app
- nodemodules:/usr/src/app/node_modules
ports:
- ${SERVER_PORT}:${SERVER_PORT}
depends_on:
- redis
- postgres
redis:
container_name: redis
image: redis:5
postgres:
container_name: postgres
image: postgres:12
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_DB: ${DB_DATABASE_NAME}
PG_DATA: /var/lib/postgresql/data
ports:
- 5432:5432
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
nodemodules: {}
scripts from package.json:
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
