I'm attempting to use Docker Compose to bring together a number of Node.js apps in my development environment. I'm running into an issue, however, with node_modules.
Here's what's happening:
- npm installis run as part of the- Dockerfile.
- I do not have node_modulesin my local directory. (I shouldn't because the installation of dependencies should happen in the container, right? It seems to defeat the purpose otherwise, since I'd need to have Node.js installed locally.)
- In docker-compose.yml, I'm setting up avolumewith the source code.
- docker-compose buildruns fine.
- When I docker-compose up, thenode_modulesdirectory disappears in the container — I'm assuming because the volume is mounted and I don't have it in my local directory.
How do I ensure that node_modules sticks around?
Dockerfile
FROM       node:0.10.37
COPY       package.json /src/package.json
WORKDIR    /src
RUN        npm install -g grunt-cli && npm install
COPY       . /src
EXPOSE     9001
CMD        ["npm", "start"]
docker-compose.yml
api:
  build: .
  command: grunt
  links:
    - elasticsearch
  ports:
    - "9002:9002"
  volumes:
    - .:/src
elasticsearch:
  image: elasticsearch:1.5
 
    