我正在docker容器中运行node.js应用程序,并且nodemon不会在更改时重新加载。 这是我的dockerfile:
WORKDIR /app
COPY package*.json ./
RUN yarn install
COPY . /app
EXPOSE 8080
CMD ["yarn", "dev"]
我正在使用此命令构建映像:
docker image build -t test7 .
然后使用:
docker run -it -v "$(pwd)/app:/app/target_dir" test7 bash
我在容器内进行yarn dev,它会启动服务器一次,但不会重新加载。
这是package.json文件:
"name": "self-learning",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "node index.js",
"dev": "nodemon --legacy-watch index.js"
},
"dependencies": {
"cors": "^2.8.5",
"express": "^4.17.1",
"express-winston": "^4.0.3",
"multer": "^1.4.2",
"nodemon": "^2.0.2",
"pg": "^7.18.2",
"winston": "^3.2.1"
}
}
有什么办法解决吗?如何在不重建容器的情况下看到更改?
答案 0 :(得分:0)
我认为您已经这样奔跑
docker run -it -v "$(pwd)/app:/app" test7
因为您将所有文件复制到了/ app目录而不是/ app / target_dir