问题
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