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