我将 nodemon 与 docker-compose 一起使用。
这是我的 Dockerfile:
FROM node:10
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "start"]
我的 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
我的 package.json 脚本:
{
"scripts": {
"start": "nodemon --inspect=0.0.0.0 index.js"
}
}
根据我工作的 docker 容器内的代码,我的代码正在更新,但我没有任何重新加载。
如果您使用以下命令启动nodemon-L
or --legacy-watch
标志,当检测到更改时它将正确重新启动。你的脚本package.json
文件将是:
{
"scripts": {
"start": "nodemon -L --inspect=0.0.0.0 index.js"
}
}
我发现这个解决方案是对这个要点的评论:https://gist.github.com/ksmithut/e126f7ddb40b760487a17e8b569a77b5#gistcomment-2725750 https://gist.github.com/ksmithut/e126f7ddb40b760487a17e8b569a77b5#gistcomment-2725750
这可以在官方文档中找到https://github.com/remy/nodemon#application-isnt-restarting https://github.com/remy/nodemon#application-isnt-restarting
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)