在Docker容器中安装时出现'npm install'错误权限错误

gr8qqesn  于 2022-11-22  发布在  Docker
关注(0)|答案(2)|浏览(336)

我的新笔记本电脑出现了一个奇怪的错误,但旧笔记本电脑没有出现(新:M1 ARM Mac,旧版:英特尔Mac)。
我在docker-compose中将我的代码挂载为一个卷,并将容器打开,只需npm install,所有东西都将正确安装。node_modules将在卷中创建,我可以运行。在新的Mac上,它会引发权限错误。

Dock合成宗卷装入:

volumes:
- ./:/app/

奇怪的是,我可以进入它抱怨的目录,而在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

如有任何关于下一步行动的建议,我们将不胜感激。

c86crjj0

c86crjj01#

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

acruukt9

acruukt92#

我有同样的问题与牧场主桌面。

  • 苹果笔记本电脑(M2,2022)
  • Mac操作系统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$

相关问题