Use nodemon with docker and docker-compose

瘦欲@ 提交于 2020-04-12 06:17:34

问题


I'm using nodemon with docker-compose. Here is my Dockerfile:

FROM node:10

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

CMD ["npm", "start"]

My docker-compose.yml

version: '3'
services:
  app:
    build: .
    volumes:
      - .:/usr/src/app
      - /usr/src/app/node_modules
    container_name: docker-node-mongo
    restart: always
    ports:
      - 3000:3000
      - 9229:9229
    command: npm start
    links:
      - mongo
      - redis
  mongo:
    container_name: mongo
    image: mongo
    ports:
      - "27017:27017"
  redis:
    image: redis:alpine
    volumes:
      - /var/redis/data:/data    

And my package.json script:

{
  "scripts": {
    "start": "nodemon --inspect=0.0.0.0 index.js"
  }
}

According to the code inside of my working docker container, my code is updating, but I don't have any reload.


回答1:


The issue with nodemon with inspect on restart. You can read more about the issue here. You can try the work around mentioned by nodemon team

"inspect": "kill-port --port 9229 && node --inspect=0.0.0.0:9229 build/startup.js",
"start_watch_inspect": "nodemon --delay 80ms --watch build/ build/startup.js --exec 'npm run inspect'",

You can make it working using below command if you can manage without inspect

"scripts": {
    "start": "nodemon index.js"
  }

This will work with mounting the directory docker run --rm -v /home/myapp:/root --name test -it testnode

OR

copy code to docker build and update file inside the container will also work fine.



来源:https://stackoverflow.com/questions/57573992/use-nodemon-with-docker-and-docker-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!