2

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).

Pawel
  • 1,672
  • 2
  • 18
  • 24
  • Possible duplicate of [Docker-compose: node\_modules not present in a volume after npm install succeeds](http://stackoverflow.com/questions/30043872/docker-compose-node-modules-not-present-in-a-volume-after-npm-install-succeeds) – FrederikNS Feb 29 '16 at 12:27

1 Answers1

2

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

dnephin
  • 25,944
  • 9
  • 55
  • 45