Missing dependencies folder after successful npm install in Docker volume mount

My Setup

I’m working with a multi-service application that includes:

  • api/ - Python Flask server running on port 5000 with SQLite database
  • processor/ - Contains app.js file that handles background tasks. The Flask server communicates with this service via JSON API on port 8080. This service uses Redis for caching and saves files to processor/uploads/

My issue is specifically with the processor service.

processor/Dockerfile

FROM node:0.12

WORKDIR /processor

COPY package.json /processor/
RUN npm install

COPY . /processor/

docker-compose.yml

redis:
    image: redis
processor:
    build: ./processor
    command: npm start
    ports:
        - "8080:8080"
    volumes:
        - processor/:/processor/
    links:
        - redis

The Problem

When I execute docker-compose build, everything appears to work correctly. All npm packages get installed to /processor/node_modules as expected:

npm WARN package.json [email protected] No README data

> [email protected] install /processor/node_modules/screenshot-tool/node_modules/phantomjs
> node install.js

However, when I run docker-compose up, I get this error:

processor_1 | Error: Cannot find module 'lodash'
processor_1 |     at Function.Module._resolveFilename (module.js:336:15)
processor_1 |     at Function.Module._load (module.js:278:25)
processor_1 |     at Module.require (module.js:365:17)
processor_1 |     at require (module.js:384:17)
processor_1 |     at Object.<anonymous> (/processor/app.js:1:75)

The /processor/node_modules directory is completely empty both in the container and on the host machine.

If I manually run npm install on my host machine, everything works fine. But I want the container to manage all dependencies automatically.

What could be causing this issue? All required packages are properly listed in my package.json file.

Your volume mount is wiping out the /processor directory, including the node_modules that Docker built. When you mount a volume, it overwrites everything in that folder. Fix this by adding an anonymous volume for node_modules in your docker-compose.yml: volumes: - processor/:/processor/ - /processor/node_modules. This way your source code updates but the dependencies stay intact.

Had the same problem with a Dockerized app. When you mount a volume, it wipes out everything in /processor, including the node_modules from your build. I tried running npm install after mounting the volume, but that’s messy. Better options: create a separate volume just for node_modules, or restructure your project so source files live in a subdirectory. Docker’s doing what it’s supposed to do, but it definitely messes with your dependencies.

your volume mount’s wiping out the node_modules that were created during the build. that processor/:/processor/ line replaces everything in /processor with your host directory - which doesn’t have node_modules. try excluding it with another volume like - /processor/node_modules or just move your source to a subdirectory.