创建一个Dockerfile来安装我们创建的节点框架(根据我之前发布的 here): # Install dependencies and nodejsRUN apt-get updateRUN apt-get install -y python-software-properties python g++ makeRUN add-apt-repository ppa:chri
# 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希望不以root身份运行 – 有没有办法将一系列sudo useradd命令链接起来创建一个具有sudo权限的临时用户,然后我可以切换到USER来运行npm install?
编辑:更新上面的内容,现在成功创建用户并进入npm安装行并窒息后得到此问题:
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>要解决“尝试解锁”问题,请先尝试通过发出来清除npm缓存
npm cache clean
之后,跑
npm install