I am working on a docker image for a development environment for my Node.js app. When running the docker image, a volume is mounted so that the source code of my app is shared with the container from the host. The problem I am running into is that, unlike most Node.js projects, I keep the node_modules/ under version control (as recommended here http://www.futurealoof.com/posts/nodemodules-in-git.html).

I need to inject the node_modules/ directory into the container during build using ADD to build the binary modules, and then somehow get my app to use them during the running of the docker container, after the volume has been mounted.

# Docker official ubuntu 12.04 LTS
FROM ubuntu:12.04

# See: https://launchpad.net/~chris-lea/+archive/node.js/
ENV NODEJS_VERSION 0.10.29-1chl1~precise1

# add updated node.js defacto official repository
RUN apt-get update
RUN apt-get install --yes python-software-properties
RUN add-apt-repository ppa:chris-lea/node.js

# install node.js
RUN apt-get update
RUN apt-get install --yes nodejs=${NODEJS_VERSION}

# install other dependencies via apt...

# copy files to temp directory and rebuild binary node.js modules
ADD ./node_modules /tmp/web/
WORKDIR /tmp/web
RUN npm rebuild

# expose port for app and start it
EXPOSE 5900

WORKDIR /app

# HELP: better way than copying here?
CMD cp -r /tmp/web/node_modules . && ./node_modules/.bin/forever \
  --watch app.js

closed as off-topic by Gerald Schneider, MadHatter, ThoriumBR, Jenny D, Dave M Nov 25 '17 at 13:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – Gerald Schneider, MadHatter, ThoriumBR, Jenny D, Dave M
If this question can be reworded to fit the rules in the help center, please edit the question.

You could just as easily set your working directory to (i.e.) /app, mount your volume into /app inside the container, run npm rebuild from there right?

  • you mean run npm rebuild when you start the container? what if you have a CMD or ENTRYPOINT – kevzettler Dec 26 '14 at 17:25
  • You could use a seperate build container for that purpose or otherwise just allow the container to start arbitrary other commands via a seperate runner yes – Gekkie Dec 27 '14 at 19:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.