Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performing a npm install via Docker on a windows host

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 !

like image 359
jiboulex Avatar asked Jan 22 '16 09:01

jiboulex


2 Answers

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.

like image 149
Tomasz Jakub Rup Avatar answered Oct 19 '22 13:10

Tomasz Jakub Rup


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.

like image 31
Victor Roetman Avatar answered Oct 19 '22 13:10

Victor Roetman