Node.js + Docker Compose: node_modules disappears -


i'm attempting use docker compose bring number of node.js apps in development environment. i'm running issue, however, node_modules.

here's what's happening:

  1. npm install run part of dockerfile.
  2. i not have node_modules in local directory. (i shouldn't because installation of dependencies should happen in container, right? seems defeat purpose otherwise, since i'd need have node.js installed locally.)
  3. in docker-compose.yml, i'm setting volume source code.
  4. docker-compose build runs fine.
  5. when docker-compose up, node_modules directory disappears in container — i'm assuming because volume mounted , don't have in local directory.

how ensure 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 

due the way node.js loads modules, place node_modules higher in source code path. example, put source @ /app/src , package.json in /app, /app/node_modules they're installed.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -