【问题标题】:EEXIST: file already exists for installing npm package globally in DockerfileEEXIST:文件已经存在,用于在 Dockerfile 中全局安装 npm 包
【发布时间】:2021-03-25 19:48:43
【问题描述】:

我正在尝试通过创建一个简单的 nodejs 映像来学习 docker:

# Dockerfile
FROM node:10
RUN npm install -g yarn
EXPOSE 8080
WORKDIR /usr/src/app

当我运行docker build -t "node10" . 时,出现以下错误:

 > [2/3] RUN npm install -g yarn:
#5 2.007
#5 2.007 > yarn@1.22.10 preinstall /usr/local/lib/node_modules/yarn
#5 2.007 > :; (node ./preinstall.js > /dev/null 2>&1 || true)
#5 2.007
#5 2.565 npm ERR! code EEXIST
#5 2.573 npm ERR! syscall symlink

#5 2.581 npm ERR! path ../lib/node_modules/yarn/bin/yarn.js
#5 2.581 npm ERR! dest /usr/local/bin/yarn
#5 2.582 npm ERR! errno -17
#5 2.589 npm ERR! EEXIST: file already exists, symlink '../lib/node_module
s/yarn/bin/yarn.js' -> '/usr/local/bin/yarn'
#5 2.589 npm ERR! File exists: /usr/local/bin/yarn
#5 2.590 npm ERR! Remove the existing file and try again, or run npm
#5 2.591 npm ERR! with --force to overwrite files recklessly.
#5 2.598
#5 2.599 npm ERR! A complete log of this run can be found in:
#5 2.599 npm ERR!     /root/.npm/_logs/2021-03-25T05_08_51_089Z-debug.log

我该如何解决这个错误?

【问题讨论】:

  • 出于某种原因,对我来说,只需删除 RUN npm install -g yarn 就可以了,就像不需要安装纱线一样

标签: node.js docker npm


【解决方案1】:

标准的 Docker Hub node 镜像已经包含 Yarn;不需要单独安装。

~% docker run --rm node:10 yarn --version
1.13.0

只需 COPY 你的 package.jsonyarn.lockRUN yarn install。删除RUN npm install -g yarn这一行,没必要,你的错误是和预装的Yarn冲突。

【讨论】:

    【解决方案2】:
    FROM node:10
    WORKDIR /usr/src/app
    COPY package*.json ./
    RUN npm install
    COPY . .
    CMD [ "npm", "run", "start" ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-09
      • 1970-01-01
      • 2021-09-27
      • 2016-06-21
      • 2019-12-22
      • 2017-11-05
      • 2020-10-23
      • 1970-01-01
      相关资源
      最近更新 更多