【发布时间】:2021-04-10 05:47:31
【问题描述】:
我有一个运行良好的 Dockerfile:
FROM node:10
RUN npm set unsafe-perm true
RUN npm install -g '@oresoftware/r2g@0.0.132'
但与上述 Dockerfile 相同的 CircleCI config.yml 文件不起作用:
{
"version": 2,
"jobs": {
"build": {
"docker": [
{
"image": "circleci/node:10"
}
],
"steps": [
{
"run": "npm set unsafe-perm true"
},
{
"run": "npm install -g --loglevel=warn '@oresoftware/r2g@0.0.132'"
}
]
}
}
}
我在使用上述 config.yml 文件的 CircleCI 上收到以下错误:
#!/bin/bash -eo pipefail
npm install -g --loglevel=warn @oresoftware/r2g
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
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 (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /home/circleci/.npm/_logs/2018-06-18T18_26_53_651Z-debug.log
Exited with code 243
CircleCI 2.0 应该使用 Docker,所以我不确定为什么会发生此权限错误。
【问题讨论】:
-
请注意,我不应该为此使用
sudo,但如果我确实使用sudo,在CircleCI 上也会失败并出现不同的权限错误。 -
只是好奇,我自己是 CircleCI 的新用户 - 你不是两次执行相同的步骤吗?一次在 Docker 构建中,一次在 CircleCI 步骤中?你不应该只做一次吗? (我会在 CircleCI 步骤中说)
-
我不确定你的意思,在上面的配置中,
"steps"是"build"的一部分,对吧? -
我可能会误解,但我假设 Docker 映像将构建并在构建时执行这两个
RUN npm步骤,然后 CircleCI 将尝试在 Docker 映像上分别执行steps下的操作- 与构建映像时已经运行的步骤基本相同。 -
啊Dockerfiles不完全一样,你发布的那个是从
node:10派生的,圈子上用的是circleci/node:10。不同之处在于,circleci 节点镜像落入circleci用户,因此失去了root 权限。这在circleci/node docker hub page (point 4 under the heading "Why") 中有描述。所以相当于node-based image would look like this。这个 dockerfile 产生与 circle 相同的结果。
标签: node.js docker npm circleci circleci-2.0