Performing a npm install via Docker on a windows host
Asked Answered
I

2

9

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

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

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

Trying to install npm dependencies (shoots the error):

docker exec -it dev_tools_container npm install

Thank you for your time !

Interstitial answered 22/1, 2016 at 9:18 Comment(0)
M
4

Instead of

RUN npm install --global gulp -y

use

RUN sudo npm install --global gulp -y

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

Or install gulp before switch user to node.

USER node
RUN npm install --global gulp -y

EDIT:

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

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

Replace VM_NAME and SHARE_NAME and restart VirtualBox.

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

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.

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

Mantissa answered 22/1, 2016 at 9:34 Comment(9)
Thank you for your answer ! I tried but it changes nothing. This docker container works fine on a linux host. I think this is a trouble of shared folder. Also it is not the gulp or bower install that create problems :\Interstitial
thank you again. I tried with the --no-bin-link option but without success. I'll see what I can do with symlinksInterstitial
I ran the command ./VBoxManage.exe setextradata default VBoxInternal2/SharedFoldersEnableSymlinksCreate/c/Users 1 in the /c/Program Files/Oracle/VirtualBox folder but it had no effect :(Interstitial
Your virtual machine has name default and shared forder has name c/Users? And You restart VirtualBox after this operation?Mantissa
Yep exactly. Virtualbox told me that changes were made, I saved them and restart.Interstitial
Let's try to simplify: rename share folder name to cUsers. Maybe VirtualBox have problem with this name?Mantissa
Try to run VirtualBox "as an administrator"Mantissa
again, thank you so much for your help, sorry for the answer delay, my user is already in the administrator group, I tried to re-do all the steps including SharedFoldersEnableSymlinksCreate and executing virtualbox as an admin but I had the same issue..Interstitial
Strangely, running the global npm commands went smoothly for me, but when trying npm install (which installs assets locally) i get thousands of errors about file permissions, mostly.Beeves
M
3

You can mount node_modules as a volume, so it will be a Linux filesystem inside the Docker container. Add this to your Dockerfile:

VOLUME /var/www/site/node_modules

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

Microcurie answered 1/8, 2016 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.