簡體   English   中英

EEXIST:文件已經存在,用於在 Dockerfile 中全局安裝 npm package

[英]EEXIST: file already exists for installing npm package globally in Dockerfile

我正在嘗試通過創建一個簡單的 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

我該如何解決這個錯誤?

FROM node:10
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "npm", "run", "start" ]

標准的 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 沖突。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM