【问题标题】:Docker Container npm ERR! Internal watch failed: Circular symlink detectedDocker 容器 npm 错误!内部监视失败:检测到循环符号链接
【发布时间】:2021-01-03 12:45:16
【问题描述】:

我创建了一个 express API,它会在端口 5000 上正常运行。当我把它放在 Docker 容器上时,它一开始会运行,但后来我收到这样的错误消息。

> nodejs-express-sequelize-postgresql@1.0.0 start
> nodemon server.js

[nodemon] 2.0.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
(node:33) [SEQUELIZE0004] DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:33) Warning: Accessing non-existent property 'Sequelize' of module exports inside circular dependency
Server is running on port 5000.
Executing (default): CREATE TABLE IF NOT EXISTS "simplenims" ("id"   SERIAL , "nim" VARCHAR(255), "nama" VARCHAR(255), "status" BOOLEAN, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));
[nodemon] Internal watch failed: Circular symlink detected: "/usr/bin/X11" points to "/usr/bin"
npm ERR! code 1
npm ERR! path /
npm ERR! command failed
npm ERR! command sh -c nodemon server.js

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-12-14T11_53_26_130Z-debug.log

这是我的 Dockerfile 的样子

FROM node:latest

WORKDIR /

COPY package*.json ./
 
RUN npm install

COPY . .

ENV port=5000

EXPOSE 5000

CMD ["npm", "start"]

我按照 Docker 的文档制作了 Dockerfile。有什么问题或者我需要添加 Doccerfile 吗?

【问题讨论】:

    标签: node.js docker npm


    【解决方案1】:

    Nodemon 监视项目根目录中的所有文件。为了避免这个问题,你可以在项目根目录下创建nodemon.js文件,内容如下:

    {
      "ext": "js"
    }
    

    这个答案来自 Github issue。真的和你的问题很相似。

    [Github Issue] Internal watch failed: Circular symlink detected

    [Original Answer]

    【讨论】:

      【解决方案2】:

      这与nodemon有关。以下是解决方法-

      像这样使用 dockerfile:

       FROM node:14.15.0
       WORKDIR /app 
       COPY . /app 
       RUN npm install 
       CMD npm run dev
      

      构建映像,然后在具有交互式终端(可选)的容器中运行它,将卷从当前主机目录(pwd)挂载到容器中的 WORKDIR(/app):

      docker build -t imagename:tag .
      docker run -it -p 1234:1234 -v $(pwd):/app imagename:tag
      

      或者,使用 docker-compose.yml

      version: '3.6'
      services:
        server:
          build: .
          volumes:
          - .:/app
          ports:
          - "3000:3000"
      

      然后运行

      docker-compose up --build
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-04-06
        • 2018-10-08
        • 1970-01-01
        • 2016-04-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-24
        相关资源
        最近更新 更多