构建Node/Docker时无法获取uid/gid [英] Could not get uid/gid when building Node/Docker

查看:261
本文介绍了构建Node/Docker时无法获取uid/gid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Dockerfile正在使用alpine并在全球范围内安装react-scripts.尝试安装时,失败并显示无法获取uid/gid"错误.我在npm install -g命令中添加了"--unsafe-perm"选项. docker容器已成功创建,但是容器中的权限已通过消息通知已安装的文件.我看到所有用户名和组都设置为1000.我尝试在安装步骤之前将以下命令添加到Dockerfile中,但这无济于事.

My Dockerfile is using alpine and globally installing react-scripts. When it tries to install it, it fails with "could not get uid/gid" error. I added the "---unsafe-perm" option to the npm install -g command. The docker container is successfully created, but the permissions in the container are messaged up for the installed files. I see the username and group set to 1000 for all of them. I tried adding the following command to the Dockerfile right before the install step but that didn't help.

RUN npm -g config set user root

构建错误

Error: could not get uid/gid
[ 'nobody', 0 ]

    at /usr/local/lib/node_modules/npm/node_modules/uid-number/uid-number.js:37:16
    at ChildProcess.exithandler (child_process.js:296:5)
    at ChildProcess.emit (events.js:182:13)
    at maybeClose (internal/child_process.js:961:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:250:5)
TypeError: Cannot read property 'get' of undefined
    at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:205:18)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:76:20
    at cb (/usr/local/lib/node_modules/npm/lib/npm.js:228:22)
    at /usr/local/lib/node_modules/npm/lib/npm.js:266:24
    at /usr/local/lib/node_modules/npm/lib/config/core.js:83:7
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/npm/lib/config/core.js:82:13
    at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25)
    at afterExtras (/usr/local/lib/node_modules/npm/lib/config/core.js:173:20)
    at Conf.<anonymous> (/usr/local/lib/node_modules/npm/lib/config/core.js:231:22)
/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:205
  if (npm.config.get('json')) {
                 ^

TypeError: Cannot read property 'get' of undefined
    at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:205:18)
    at process.emit (events.js:182:13)
    at process._fatalException (internal/bootstrap/node.js:472:27)
ERROR: Service 'sample-app' failed to build: The command '/bin/sh -c npm install react-scripts@1.1.1 -g' returned a non-zero code: 

Dockerfile

Dockerfile

/usr/src/app # cat Dockerfile
# build environment
FROM node:10-alpine as builder
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json
RUN npm install
RUN npm install react-scripts@1.1.1 -g 
COPY . /usr/src/app
RUN npm run build

# production environment
FROM nginx:1.13.9-alpine
COPY --from=builder /usr/src/app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

推荐答案

UPD 已修复

UPD Fixed in nodejs@12.4.0?

检查是否链接到 nodejs/docker-node问题813 :

根本原因似乎是:线程堆栈大小

glibc上新线程的默认堆栈大小是根据控制主线程堆栈(RLIMIT_STACK)的资源限制确定的.
它通常最终为2-10 MB.

The default stack size for new threads on glibc is determined based on the resource limit governing the main thread’s stack (RLIMIT_STACK).
It generally ends up being 2-10 MB.

有三种可能的解决方案:

There three possible solutions:

  • Talk to Alpine teams to fix it. There were some discussions already
  • Fix it in the node docker alpine image as follows
  • Set default npm_config_unsafe_perm=true in the docker image as a workaround until it's fixed.

您已经尝试过第三种选择,但也请考虑:

You already tried the third option, but consider also:

或者,您应该切换到苗条(Debian)变体,直到由Alpine团队解决此问题为止.

Alternatively, you should switch to the slim (Debian) variant until this get's fixe upstream by the Alpine team.

这篇关于构建Node/Docker时无法获取uid/gid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆