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:
npm installrun part ofdockerfile.- i not have
node_modulesin 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.) - in
docker-compose.yml, i'm settingvolumesource code. docker-compose buildruns fine.- when
docker-compose up,node_modulesdirectory 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
Post a Comment