【发布时间】:2022-01-23 08:07:54
【问题描述】:
我试图找到解决方案很长一段时间 - 在更新例如 index.js 时在 docker 中重新加载 nodemon。我有windows 10。 我有 docker 的节点项目: proj/backend/src/index.js:
const express = require('express')
const app = express()
app.get('/', (req, res) => {
res.send('Hello world.')
})
const port = process.env.PORT || 3001
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
项目/后端/package.json:
{
"scripts": {
"start": "node ./bin/www",
"start:legacy": "nodemon --legacy-watch -L --watch src src/index.js"
},
"dependencies": {
"express": "^4.17.2"
},
"devDependencies": {
"nodemon": "^2.0.15"
}
}
proj/backend/dev.Dockerfile:
FROM node:lts-alpine
RUN npm install --global nodemon
WORKDIR /usr/src/app
COPY . .
RUN npm ci
EXPOSE 3001
ENV DEBUG=playground:*
CMD npm run start:legacy
proj/docker-compose.dev.yml:
version: '3.8'
services:
backend:
image: backend-img
build:
context: ./backend
dockerfile: ./dev.Dockerfile
ports:
- 3001:3001
environment:
- PORT=3001
【问题讨论】: