[英]How do you setup Nodemon in a Docker container?
I am trying to setup Nodemon in a Docker container.我正在尝试在 Docker 容器中设置 Nodemon。 It says that nodemon is running, but when I change code in my index.js file it does not reload like it does outside of docker.
它说 nodemon 正在运行,但是当我更改 index.js 文件中的代码时,它不会像在 docker 之外那样重新加载。 I've tried adding -L to the command, but no luck.
我尝试将 -L 添加到命令中,但没有运气。 I've also tried installing nodemon in the docker file instead, but no luck.
我也尝试在 docker 文件中安装 nodemon,但没有运气。
I have to do docker-compose up --build anytime I change my index.js file.每当我更改 index.js 文件时,我都必须执行 docker-compose up --build。
Any ideas?有任何想法吗?
Here is my file structure:这是我的文件结构:
-api
-node_modules
-.dockerignore
-Dockerfile
-index.js
-package.json
-package-lock.json
-docker-compose.yml
docker-compose.yml: docker-compose.yml:
version: '3.4'
services:
api:
build:
context: ./api
container_name: api
environment:
- PORT=3001
volumes:
- ./api/src:/usr/app/src
ports:
- '3001:3001'
command: npm run dev
Dockerfile: Dockerfile:
FROM node:14.15.2-alpine3.12
WORKDIR /usr/app
COPY package*.json ./
RUN npm install
COPY . .
package.json: package.json:
{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"express": "^4.17.1"
},
"scripts": {
"dev": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"nodemon": "^2.0.6"
}
}
I FIGURED IT OUT!!!我想到了!!!
After a lot of trial and error.经过大量的试验和错误。 It has to do with my volumes in my docker compose as well as nodemon.
这与我的 docker compose 以及 nodemon 中的卷有关。 Not 100% sure why any insight would be helpful too.
不是 100% 确定为什么任何洞察力也会有所帮助。
The fix was to change my volume from解决方法是将我的音量从
- ./api/src:/usr/app/src
to:至:
- ./api:/usr/src/app
Then I had to add the -L flag to my nodemon command in order for it to reload.然后我必须将 -L 标志添加到我的 nodemon 命令中才能重新加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.