2

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

1 Answer 1

0

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?

2
  • you mean run npm rebuild when you start the container? what if you have a CMD or ENTRYPOINT
    – kevzettler
    Dec 26, 2014 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, 2014 at 19:37

Not the answer you're looking for? Browse other questions tagged .