Performing npm installation through Docker on a Windows host

I am trying to create a docker dev tool container for a devlopement environment on a Windows host through the docker toolbar, but I have some problems running the npm install command. It worked fine on the 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 

Here is my Docker file:

 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 

In the Docker quick launch terminal, I use the following commands:

Image building (works great)

 docker build -t dev_tools . 

Building a container (works great)

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

Trying to install npm dependencies (removes the error):

 docker exec -it dev_tools_container npm install 

Thank you for your time!

+7
docker npm boot2docker
source share
2 answers

Instead

 RUN npm install --global gulp -y 

using

 RUN sudo npm install --global gulp -y 

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

Or install gulp before switching the user to node.

 USER node RUN npm install --global gulp -y 

EDIT:

boot2docker is based on VirtualBox . For security reasons, Virtualbox does not allow symbolic links in public folders.

To enable symbolic links, you must set VBoxInternal2 / SharedFoldersEnableSymlinksCreate / SHARE_NAME to 1 . (Here's a link to a description of how to do this on Vargrant: Symbolic links and synchronized folders in Vagrant )

 VBoxManage setextradata VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME 1 

Replace VM_NAME and SHARE_NAME and restart VirtualBox.

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

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

EDIT 2

By default, Windows 7 security policy does not allow the creation of symbolic links, as this is a potential security risk. If the user is not a member of the Administrators group, run secpol.msc and go to Local Policies - User Rights Assignments and add the user to Create symbolic links .

If your user belongs to the Administrators group, start VirtualBox using Run as administrator .

+3
source share

You can set node_modules as the volume, so this will be the Linux file system inside the Docker container. Add this to your Docker file:

VOLUME /var/www/site/node_modules

You will see the directory in C:Users/Public/site/node_modules , because it is necessary for the mount point, but you will not see any content if you are not inside the container.

0
source share

All Articles