I have an app with the following services:
web/
– holds and runs a python 3 flask web server on port 5000. Uses sqlite3.worker/
– has anindex.js
file which is a worker for a queue. the web server interacts with this queue using a json API over port9730
. The worker uses redis for storage. The worker also stores data locally in the folderworker/images/
Now this question only concerns the worker
.
worker/Dockerfile
FROM node:0.12
WORKDIR /worker
COPY package.json /worker/
RUN npm install
COPY . /worker/
docker-compose.yml
redis:
image: redis
worker:
build: ./worker
command: npm start
ports:
- "9730:9730"
volumes:
- worker/:/worker/
links:
- redis
When I run docker-compose build
, everything works as expected and all npm modules are installed in /worker/node_modules
as I’d expect.
npm WARN package.json unfold@1.0.0 No README data
> phantomjs@1.9.2-6 install /worker/node_modules/pageres/node_modules/screenshot-stream/node_modules/phantom-bridge/node_modules/phantomjs
> node install.js
<snip>
But when I do docker-compose up
, I see this error:
worker_1 | Error: Cannot find module 'async'
worker_1 | at Function.Module._resolveFilename (module.js:336:15)
worker_1 | at Function.Module._load (module.js:278:25)
worker_1 | at Module.require (module.js:365:17)
worker_1 | at require (module.js:384:17)
worker_1 | at Object.<anonymous> (/worker/index.js:1:75)
worker_1 | at Module._compile (module.js:460:26)
worker_1 | at Object.Module._extensions..js (module.js:478:10)
worker_1 | at Module.load (module.js:355:32)
worker_1 | at Function.Module._load (module.js:310:12)
worker_1 | at Function.Module.runMain (module.js:501:10)
Turns out none of the modules are present in /worker/node_modules
(on host or in the container).
If on the host, I npm install
, then everything works just fine. But I don’t want to do that. I want the container to handle dependencies.
What’s going wrong here?
(Needless to say, all packages are in package.json
.)