Pawel
Pawel

Reputation: 1692

docker-compose dosen't see node_modules from npm

I guess I'm not the first one who has this problem, but I don't see sultion which will work for me.

docker-compose.yml file

web:
build: .
volumes:
   - .:/src
ports:
   - "3000:3000"

Dockerfile

FROM node:0.12

RUN npm install -g mocha

RUN mkdir /src
WORKDIR /src
ADD package.json /src/package.json
RUN npm install
COPY . /src

EXPOSE 3000
CMD node server.js

Aand after successfull build while running via docker-compose up, I have and error:

web_1 | Error: Cannot find module 'express'
web_1 |     at Function.Module._resolveFilename (module.js:336:15)
web_1 |     at Function.Module._load (module.js:278:25)
web_1 |     at Module.require (module.js:365:17)
web_1 |     at require (module.js:384:17)
web_1 |     at Object.<anonymous> (/src/server.js:1:77)
web_1 |     at Module._compile (module.js:460:26)
web_1 |     at Object.Module._extensions..js (module.js:478:10)
web_1 |     at Module.load (module.js:355:32)
web_1 |     at Function.Module._load (module.js:310:12)
web_1 |     at Function.Module.runMain (module.js:501:10)

Any ideas what can be wrong ? I've already spend on this task over 3h and I have no clue why this dosen't work (newbie to docker).

Upvotes: 2

Views: 848

Answers (1)

dnephin
dnephin

Reputation: 28070

I think you're overriding the directory by using a volume: - .:/src.

If you do that you need to run npm install on the host

Upvotes: 2

Related Questions