Serhat
Serhat

Reputation: 3

Docker not reload nodejs app even I use nodemon?

I have a problem which it took my two days and still not find any solution. I am developing an express app with docker but when make code changes docker not reload the app. I have to docker-compose down and up to see the changes. I search a lot on the internet but can't find any solution to fit my problem.

I will very grateful if you help me. Thanks a lot.

My docker directory like this:

/api
   Dockerfile
/mongo
   Dockerfile
docker-compose.yml

Here is my /api/Dockerfile code

FROM node:latest

RUN mkdir app
WORKDIR /app
COPY . /app
RUN npm install
EXPOSE 3000
CMD ["npm", "start"]

Here is my compose file

version: '2'
services:
  api:
    container_name: ats-express
    build: ./api
    volumes:
      - ../ats-api:/app
    ports:
      - "3000:3000"
    links:
      - mongo
    depends_on:
      - mongo

    restart: always

and here is my npm start script in package.json at express-api

"scripts": {
    "start": "nodemon ./bin/www"
  }

Upvotes: 0

Views: 714

Answers (1)

Felix Fong
Felix Fong

Reputation: 985

This just so happened to me before, and my way of resolving this issue is to add a --legacy-watch flag to the nodemon command

"scripts": {
    "start": "nodemon --legacy-watch ./bin/www"
}

Upvotes: 4

Related Questions