在Windows主机上通过Docker执行npm安装 [英] Performing a npm install via Docker on a windows host

查看:274
本文介绍了在Windows主机上通过Docker执行npm安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过docker toolbox在Windows主机上为开发环境创建docker dev工具容器,但是在运行npm install命令时遇到了一些麻烦. 在Linux主机上运行正常,但在Windows主机上,出现以下错误:

I'm trying to create a docker dev tools container for a devlopement environment on a windows host via docker toolbox but I have some trouble running the npm install command. It worked fine on a linux host but on the windows host I got the following error :

npm ERR! Linux 4.1.13-boot2docker
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v5.5.0
npm ERR! npm  v3.3.12
npm ERR! path /var/www/site/.npm/gulp/3.9.0/package.tgz.e87c24357cd6065ee71ce44c6f23673b
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename

npm ERR! ETXTBSY: text file is busy, rename '/var/www/site/.npm/gulp/3.9.0/package.tgz.e87c24357cd6065ee71ce44c6f23673b' -> '/var/www/site/.npm/gulp/3.9.0/package.tgz'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>
npm ERR! Linux 4.1.13-boot2docker
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v5.5.0
npm ERR! npm  v3.3.12
npm ERR! path npm-debug.log.39d944b679d410e5293d6721cbc8287a
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename

npm ERR! ETXTBSY: text file is busy, rename 'npm-debug.log.39d944b679d410e5293d6721cbc8287a' -> 'npm-debug.log'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/site/npm-debug.log

这是我的Dockerfile:

Here is my Dockerfile :

FROM node:latest

RUN apt-get update
RUN apt-get install vim -y
RUN useradd -ms /bin/bash node
RUN echo "fs.inotify.max_user_watches=100000" > /etc/sysctl.conf

ADD . /var/www/site
RUN chown -R node:node /var/www/site
RUN chown -R node:node /usr/local/lib/node_modules
RUN chown -R node:node /usr/local/bin

USER node
ENV HOME /var/www/site

WORKDIR /var/www/site

RUN npm install -g bower
RUN npm install --global gulp -y

EXPOSE 80 8080 35729

在Docker快速入门终端中,我使用以下命令:

In Docker quickstart terminal, I use the following commands :

构建图像(可以正常工作)

Building the image (works fine)

docker build -t dev_tools .

构建容器(可以正常工作)

Building the container (works fine)

docker run --name=dev_tools_container -t --rm -v "//c/Users/Public/site:/var/www/site" --net=host dev_tools

尝试安装npm依赖项(解决错误):

Trying to install npm dependencies (shoots the error):

docker exec -it dev_tools_container npm install

谢谢您的时间!

推荐答案

代替

RUN npm install --global gulp -y

使用

RUN sudo npm install --global gulp -y

您尝试将gulp作为全局软件包从用户node(不是超级用户)安装.

You try to install gulp as a global package from user node (not superuser).

或在将用户切换到节点之前安装gulp.

Or install gulp before switch user to node.

USER node
RUN npm install --global gulp -y

boot2docker 基于 VirtualBox .出于安全原因,Virtualbox不允许共享文件夹上的符号链接.

boot2docker is based on VirtualBox. Virtualbox does not allow symlinks on shared folders for security reasons.

要启用符号链接,必须将 VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME 设置为 1 . (此处是描述如何在Vargrant上进行操作的链接: Symbolic链接和Vagrant中的同步文件夹)

To enable symlinks You must set VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME to 1. (Here is link to description how to do it on Vargrant: Symbolic links and synced folders in Vagrant)

VBoxManage setextradata VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME 1

替换VM_NAME和SHARE_NAME,然后重新启动VirtualBox.

Replace VM_NAME and SHARE_NAME and restart VirtualBox.

另一种解决方案是将--no-bin-link添加到npm:

Another solution is add --no-bin-link to npm:

RUN npm install -g bower --no-bin-link
RUN npm install --global gulp -y --no-bin-link

编辑2

默认情况下,Windows 7安全策略不允许创建符号链接,因为它是潜在的安全威胁.如果用户不在Administrators组中,请运行 secpol.msc 并导航至本地策略-用户权限分配,然后将您的用户添加到创建符号链接.

EDIT 2

By default Windows 7 security policy does not allow creating symlinks as it's a potential security threat. If user is not in Administrators group run secpol.msc and navigate to Local Policies-User Rights Assignments and add your user to Create symbolic links.

如果您的用户属于Administrators组,则以以管理员身份运行开始VirtualBox.

If your user belongs to Administrators group then start VirtualBox with Run as Administrator.

这篇关于在Windows主机上通过Docker执行npm安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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