EACCES:权限被拒绝,打开'/usr/local/lib/node_modules/npm/bin/npm-cli.js' [英] EACCES: permission denied, open '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
问题描述
您好,先生,我是docker的新手,我使用的是ubuntu budgie(linux)20.04,我的docker版本是
Docker版本18.09.9,内部版本1752eb3
i已使用snap软件包管理器安装了docker,路径是这样的
/snap/bin/docker.machine /snap/bin/docker.compose / snap / bin / docker / snap /bin/docker.help
我已经在主机中通过以下链接安装了nodejs和npm
nodejs安装链接
我正在通过与docker制作单个nodejs express应用程序来学习docker。这是我的Dockerfile
Hello sir i am new to docker, i am using ubuntu budgie(linux) 20.04 my docker version is
Docker version 18.09.9, build 1752eb3
i have install docker using snap package manager and the path is like this
/snap/bin/docker.machine /snap/bin/docker.compose /snap/bin/docker /snap/bin/docker.help
I have install nodejs and npm in my host machine form this link
nodejs install link
I am learning docker by making a single nodejs express app with docker. Here is my Dockerfile
FROM node:lts
USER node
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin
WORKDIR /home/node
COPY package.json .
RUN npm install
COPY . .
CMD ['npm', 'start']
这是我的app.js文件
here is my app.js file
const express = require('express');
const app = express()
app.get('/', (req, res) => {
res.send('hello world')
})
app.listen(3000, () => {
console.log('app is renning at 3000');
})
当我开始从此dockerfile构建映像时,出现此错误
internal/fs/utils.js:230
throw err;
^
Error: EACCES: permission denied, open '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
at Object.openSync (fs.js:458:3)
at Object.readFileSync (fs.js:360:35)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1152:22)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
errno: -13,
syscall: 'open',
code: 'EACCES',
path: '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
}
The command '/bin/sh -c npm install --only=prod' returned a non-zero code: 1
请告诉我如何解决此问题。
谢谢。
Please tell me how can i fix this. Thanks.
推荐答案
我遇到了同样的问题,我尝试了几种解决方案,但唯一的解决方法是更改docker版本
I had the same problem and i tried several solution but the only one how did work is to change docker version
docker-ce|5:18.09.0~3-0~ubuntu-bionic|https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
docker-ce|18.06.3~ce~3-0~ubuntu|https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
docker-ce|18.06.2~ce~3-0~ubuntu|https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
我使用的是 5:19.03.9〜3-0〜ubuntu-bionic
,我切换了到 18.06.3〜ce〜3-0〜ubuntu
i was using 5:19.03.9~3-0~ubuntu-bionic
and i switched to 18.06.3~ce~3-0~ubuntu
我保留了相同的Dockerfile配置:
I kept the same Dockerfile config :
FROM node:10
USER root
WORKDIR /home/node/app
COPY package.json .
RUN npm install
# Bundle app source COPY . /app
EXPOSE 8080 CMD [ "node", "server.js" ]
返回:
it returns :
Step 5/8 : RUN npm install
---> Running in 5b6cd0a9a7cd
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
> nodemon@1.19.4 postinstall /home/node/app/node_modules/nodemon
> node bin/postinstall || exit 0
Love nodemon? You can now support the project via the open collective:
> https://opencollective.com/nodemon/donate
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN quiz-service@1.0.0 No description
npm WARN quiz-service@1.0.0 No repository field.
added 322 packages from 227 contributors and audited 323 packages in 21.573s
1 package is looking for funding
run `npm fund` for details
found 0 vulnerabilities
Removing intermediate container 5b6cd0a9a7cd
---> cc344027e126
Step 6/8 : COPY . /app
---> 10841d9cf0bf
Step 7/8 : EXPOSE 8080
您可以检查此链接以获取更多详细信息<重新安装docker上的href = https://docs.docker.com/engine/install/ubuntu/ rel = nofollow noreferrer>
you can check this link for more detail on reinstalling docker
这篇关于EACCES:权限被拒绝,打开'/usr/local/lib/node_modules/npm/bin/npm-cli.js'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!