当前位置: 首页 > 面试题库 >

在docker image上进行npm global安装时没有访问权限错误

龙枫
2023-03-14
问题内容

我正在尝试 使用全局安装 的firebase-tools和angular-cli 构建一个 docker镜像
。我正在为两个版本的节点构建相同的映像:6.x(LTS硼)和v8.x(最新高山)。在本地,两个映像都可以正常构建,但是当我尝试在docker
hub中构建时,只有v6.x可以成功构建。使用v8.x时,它会陷入 对未定义用户和没人用户访问权限中
。我已经在使用root用户(USER root),因为如果没有此设置(或使用USER节点),则两个图像均无法构建。

这是我的Dockerfile:

FROM node:latest

USER root

RUN npm install --quiet --no-progress -g @angular/cli@latest firebase-tools
RUN npm cache clean --force

这是输出:

Step 4/5 : RUN npm install --quiet --no-progress -g @angular/cli@latest firebase-tools

 ---> Running in fce3da11b04e

 npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
 /usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/bin/firebase
 /usr/local/bin/ng -> /usr/local/lib/node_modules/@angular/cli/bin/ng

> node-sass@4.5.3 install /usr/local/lib/node_modules/@angular/cli/node_modules/node-sass
> node scripts/install.js

Unable to save binary /usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/vendor/linux-x64-57 : { Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/vendor'
  at Object.fs.mkdirSync (fs.js:890:18)
  at sync (/usr/local/lib/node_modules/@angular/cli/node_modules/mkdirp/index.js:71:13)
  at Function.sync (/usr/local/lib/node_modules/@angular/cli/node_modules/mkdirp/index.js:77:24)
  at checkAndDownloadBinary (/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:111:11)
  at Object.<anonymous> (/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/scripts/install.js:154:1)
  at Module._compile (module.js:569:30)
  at Object.Module._extensions..js (module.js:580:10)
  at Module.load (module.js:503:32)
  at tryModuleLoad (module.js:466:12)
  at Function.Module._load (module.js:458:3)

errno: -13,
code: 'EACCES',
syscall: 'mkdir',
path: '/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/vendor' }

> grpc@1.3.8 install /usr/local/lib/node_modules/firebase-tools/node_modules/grpc > node-pre-gyp install --fallback-to-build --library=static_library
node-pre-gyp ERR! Tried to download(undefined): https://storage.googleapis.com/grpc-precompiled-binaries/node/grpc/v1.3.8/node-v57-linux-x64.tar.gz node-pre-gyp ERR! Pre-built binaries not found for grpc@1.3.8 and node@8.1.2 (node-v57 ABI) (falling back to source compile with node-gyp)
gyp WARN EACCES user "undefined" does not have permission to access the dev dir "/root/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"
gyp WARN EACCES user "nobody" does not have permission to access the dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp/8.1.2" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/firebase-tools/node_modules/grpc/.node-gyp"
(infinite loop)

问题答案:

问题是因为当NPM以nobody用户身份运行全局安装的模块脚本时,这是有意义的,但是NPM的最新版本开始将节点模块的文件权限设置为root。结果,不再允许模块脚本在其模块中创建文件和目录。

有关某些参考,请参见NPM问题#3849中的讨论。

在docker环境中有意义的一个简单变通方法是,将NPM默认全局用户设置为root,如下所示:

npm -g config set user root

之后,您就不会再有EACCES错误了。



 类似资料:
  • 问题内容: 我正在上一些大学课程,并且得到了“教学帐户”,这是我可以用来工作的学校帐户。我想在那台机器上运行需要大量计算的Numpy,matplotlib,scipy代码,但是由于我不是系统管理员,所以无法安装这些模块。 我该如何安装? 问题答案: 在大多数情况下,最好的解决方案是通过运行以下命令来依靠所谓的“用户站点”位置(有关详细信息,请参阅PEP): 以下是我原始答案提供的一种“更手动”的方

  • 我正在使用Unity游戏引擎创建游戏。在这个游戏中,我抓取了一个屏幕截图,并将其保存到Unity的默认文件夹(“Application.PersistentDataPath”): /data/data/de.mytest.mygame/files/screenshot.png 如何修复此权限问题? 编辑:创建意图如下所示:

  • 在新的centos 6.4服务器中,我使用yum安装了httpd,但当尝试使用公共ip访问服务器时,会显示“您没有访问/访问此服务器的权限” 我的文档根目录是/var/www/html 它完全有权被apache访问:[root@3html]#ll /var/www/html/-rwxr-xr-x 1 apache apache 28 6æ18 15:40 20131.php-rwxr-xr-x 1

  • 我有一个从Ubuntu软件应用程序安装的IntelliJ IDEA Ultimate 2022.1.2。它被配置为使用Maven包装器。当我在java项目上执行“安装”时(从生命周期菜单),我得到两个错误: git测试: 协议测试: maven-wrapper.properties: 同样的项目在不同的机器上运行良好。不能解决问题。

  • 我正在尝试在我的服务器上安装yeoman,但由于某些原因,我一直收到一个权限被拒绝的错误。 我曾尝试重新安装ubuntu(14.04),但没有任何效果。

  • 我自己配置了我的Apache,并试图在虚拟主机上加载phpMyAdmin,但我收到: 403禁止您没有访问/访问此服务器的权限 我的httpd.conf 和vhosts.conf: