docker:在创建新用户后,无法运行npm安装 [英] docker: having trouble running npm install after creating a new user

查看:148
本文介绍了docker:在创建新用户后,无法运行npm安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有另一个后续问题,关于在CoreOS上的Docker下安装一个基于node.js的框架,每个这篇文章

So I have another follow-up question regarding installing a node.js-based framework under Docker on CoreOS, per this post.

所以,因为 npm 关于从 package.json 通过root进行安装,我不得不创建一个非根sudo用户来安装软件包。这是我的 Dockerfile 目前看起来像我们的回购内部,构建了一个ubuntu映像:

So, because npm is finicky about installing from package.json via root, I've had to create a nonroot sudo user in order to install the package. This is what my Dockerfile currently looks like inside of our repo, building off of an ubuntu image:

# Install dependencies and nodejs
RUN apt-get update
RUN apt-get install -y python-software-properties python g++ make
RUN add-apt-repository ppa:chris-lea/node.js
RUN apt-get update
RUN apt-get install -y nodejs

# Install git
RUN apt-get install -y git

# Bundle app source
ADD . /src

# Create a nonroot user, and switch to it
RUN /usr/sbin/useradd --create-home --home-dir /usr/local/nonroot --shell /bin/bash nonroot
RUN /usr/sbin/adduser nonroot sudo
RUN chown -R nonroot /usr/local/
RUN chown -R nonroot /usr/lib/
RUN chown -R nonroot /usr/bin/
RUN chown -R nonroot /src

USER nonroot

# Install app source
RUN cd /src; npm install

我知道这是一个不利的方式来做事情,但我在另一个关于如何在这里完成npm安装的损失。当我尝试以上的时候,我们在尝试安装时收到所有软件包的错误:

I know that this is an inelegant way to do things, but I'm otherwise at a loss as to how to complete an npm install here. When I try the above, I get errors on all of the packages as they try to install:

 Error: Attempt to unlock javascript-brunch@1.7.1, which hasn't been locked
     at unlock (/usr/lib/node_modules/npm/lib/cache.js:1304:11)
     at cb (/usr/lib/node_modules/npm/lib/cache.js:646:5)
     at /usr/lib/node_modules/npm/lib/cache.js:655:20
     at /usr/lib/node_modules/npm/lib/cache.js:1282:20
     at afterMkdir (/usr/lib/node_modules/npm/lib/cache.js:1013:14)
     at /usr/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
     at Object.oncomplete (fs.js:107:15)
 If you need help, you may report this *entire* log,
 including the npm and node versions, at:
     <http://github.com/npm/npm/issues>

 ...

有关如何修改Dockerfile的任何想法?我只能假设这是一个许可的问题,与我已经设置了可能对Docker框架特有的 nonroot 用户的方式有关;我没有问题,只是在一个香草ubuntu安装上,虽然不是从脚本。

Any thoughts as to how I should modify my Dockerfile? I can only assume that this is some permissioning issue having to do with the way that I've provisioned the nonroot user above that might be particular to the Docker framework; I have no problem doing this kind of thing on just a vanilla ubuntu install, albeit not from script.

推荐答案

所以事实证明这可能是与docker的问题

so it turns out that this may be an issue with docker.

可以通过从 USER nonroot 切换到 RUN / bin / su nonroot 来解决这个问题之后,一切正常。

was able to get around this by switching from USER nonroot to RUN /bin/su nonroot instead, afterwards everything worked fine.

这篇关于docker:在创建新用户后,无法运行npm安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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