繁体   English   中英

在 docker 容器权限错误中安装时出现 `npm install` 错误

[英]`npm install` error when installing in docker container permissions error

我在我的新笔记本电脑上发生了一个奇怪的错误,但在我的旧笔记本电脑上却没有(新:M1 ARM Mac,旧:Intel Mac)。

我将我的代码作为一个卷安装在 docker-compose 中,然后启动容器,只需npm install ,一切都会正确安装。 node_modules 将在卷中创建,我可以运行。 在新 Mac 上,它会引发权限错误。

Docker-compose 卷挂载:

volumes:
- ./:/app/

这些有什么奇怪的是,我可以 go 进入它抱怨的目录,而在 docker 容器中,并创建/查看文件。

  • 节点版本:10.24.0
  • NPM 版本:5.8.0

第一个错误:

glob error { [Error: EPERM: operation not permitted, scandir '/app/node_modules/signal-exit']node_modules/shallowequal
  errno: -1,
  code: 'EPERM',
  syscall: 'scandir',
  path: '/app/node_modules/signal-exit' }

第二个错误

npm ERR! Error: EPERM: operation not permitted, open '/app/node_modules/set-value/package.json.1296712643'
npm ERR!  { [Error: EPERM: operation not permitted, open '/app/node_modules/set-value/package.json.1296712643']
npm ERR!   cause:
npm ERR!    { Error: EPERM: operation not permitted, open '/app/node_modules/set-value/package.json.1296712643'
npm ERR!      errno: -1,
npm ERR!      code: 'EPERM',
npm ERR!      syscall: 'open',
npm ERR!      path: '/app/node_modules/set-value/package.json.1296712643' },
npm ERR!   stack:
npm ERR!    'Error: EPERM: operation not permitted, open \'/app/node_modules/set-value/package.json.1296712643\'',
npm ERR!   errno: -1,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'open',
npm ERR!   path: '/app/node_modules/set-value/package.json.1296712643',
npm ERR!   parent: 'capella' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user

任何关于下一步做什么的建议将不胜感激。

我找到了答案。 我使用 colima 在新笔记本电脑上运行我的 docker 容器,而在旧笔记本电脑上我使用 docker 桌面。 我切换回来,一切又开始工作了。

我在 rancher 桌面上遇到了同样的问题。

  • MacBook Pro(13インチ、M2、2022)
  • MacOS 12.6
  • 牧场主桌面:1.5.1版
% docker run -it --rm -u 501:20 -v $(pwd):/workspace/uid -w /workspace/uid test bash
vscodes@ebb02540deaa:/workspace/uid$ id
uid=501(vscodes) gid=20(dialout) groups=20(dialout)
vscodes@ebb02540deaa:/workspace/uid$ ls -la
total 16
drwxr-xr-x 1 vscodes dialout  128 Nov 13 23:33 .
drwxr-xr-x 3 root    root    4096 Nov 13 23:37 ..
-rw-r--r-- 1 vscodes dialout  306 Nov 13 23:31 Dockerfile
-rw-r--r-- 1 vscodes dialout  124 Nov 13 23:37 README.md
vscodes@ebb02540deaa:/workspace/uid$ npx create-next-app@latest --typescript
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /home/vscodes
npm ERR! errno EACCES
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/create-next-app: EACCES: permission denied, mkdir '/home/vscodes'
npm ERR!     at /usr/share/nodejs/minipass-fetch/lib/body.js:162:15
npm ERR!     at async /usr/share/nodejs/npm/node_modules/libnpmexec/lib/index.js:108:12
npm ERR!     at async Promise.all (index 0)
npm ERR!     at async exec (/usr/share/nodejs/npm/node_modules/libnpmexec/lib/index.js:96:17)
npm ERR!     at async module.exports (/usr/share/nodejs/npm/lib/cli.js:66:5)
npm ERR!  FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/create-next-app: EACCES: permission denied, mkdir '/home/vscodes'
npm ERR!     at /usr/share/nodejs/minipass-fetch/lib/body.js:162:15
npm ERR!     at async /usr/share/nodejs/npm/node_modules/libnpmexec/lib/index.js:108:12
npm ERR!     at async Promise.all (index 0)
npm ERR!     at async exec (/usr/share/nodejs/npm/node_modules/libnpmexec/lib/index.js:96:17)
npm ERR!     at async module.exports (/usr/share/nodejs/npm/lib/cli.js:66:5) {
npm ERR!   code: 'EACCES',
npm ERR!   errno: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/home/vscodes',
npm ERR!   type: 'system'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
vscodes@ebb02540deaa:/workspace/uid$ 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM