docker开发与Node.js和二进制node_modules

我正在为我的Node.js应用程序的开发环境的泊坞窗图像工作。 在运行docker映像时,会挂载一个卷,以便我的应用程序的源代码与主机的容器共享。 我遇到的问题是,不像大多数Node.js项目,我保持node_modules /版本控制(这里推荐http://www.futurealoof.com/posts/nodemodules-in-git.html )。

我需要注入node_modules /目录到容器中,使用ADD构build二进制模块,然后以某种方式让我的应用程序在docker容器的运行过程中使用它们。

# 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 

你可以简单地将你的工作目录设置为(即)/ app,把你的卷装入容器内的/ app,从那里运行npm重build?