【问题标题】:Nodemon in docker doesn't work, also --legacy-watch -L are not workingdocker中的Nodemon不起作用,--legacy-watch -L也不起作用
【发布时间】: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

【问题讨论】:

    标签: docker nodemon


    【解决方案1】:

    如果我没记错的话,docker 容器是在进程结束时自行杀死的。使用 nodemon(和更新代码)时,进程将停止并重新启动,容器将 stop。你可以让 npm start 不是主进程,但这不是good practice

    【讨论】:

    猜你喜欢
    • 2021-11-30
    • 2016-03-29
    • 2018-12-12
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 2021-05-25
    • 2016-11-18
    相关资源
    最近更新 更多