3

I am using Nestjs Mono repo and I am trying to live reload with docker-compose.

Here is my Dockerfile

FROM node:16

ENV NODE_ENV=development
WORKDIR /app

COPY package.json ./

RUN npm install

COPY . .

And this is my service in docker-compose.yml

auth:
    build:
      context: ./
      dockerfile: ./apps/auth/Dockerfile.dev
    volumes:
      - ./apps:/app/apps
    command: npm start

Here is the start command

nest start --watch

Service is working but it is not reloading on changes

Live reloading works properly on my local machine and in container if I don't use volume.

Nestjs version: 8.1.5

Update:

I have opened an issue of nestjs/cli

All2Pie
  • 310
  • 3
  • 13
  • When live reloading worked, the bind mount volume was set, there is no way it would have worked otherwise, check that all your files are saved then relaunch `docker-compose down` and `up`, should work right away. Share some logs if any. – Ludwig Dec 22 '21 at 08:46
  • 1
    @Ludwig I checked the live reload inside docker doing SSH into the container and changing the file, but this doesn't work with bind mount. Also the changes from my code are reflected inside the container but it is not reloading. There are normal startup logs and the service is working fine. – All2Pie Dec 22 '21 at 09:54

2 Answers2

1

This may me a bit late, I had the same issue and i have tried all the available solutions and the only one that worked for me that was mentioned by @jbool24 at https://stackoverflow.com/a/73476289/4910054

solution is to start the nest with --tsc :

"start:dev": "nest start --tsc --watch"
Amrmohamed
  • 23
  • 5
0

It's late but can help others. you can add options to NestJS webpack's config

look at this reference about to config it: https://docs.nestjs.com/recipes/hot-reload

and when you did, add this options (your config file has to be like this):

module.exports = function (options) {
    options.watchOptions = {
        poll: 1000,
        aggregateTimeout: 300,
    }

    return options
};

you don't need to install dependencies that were told in the document (those are just for example). only install webpack as --save-dev