I’m having trouble with my Docker setup where npm packages get installed during the build process but disappear when I mount a volume.
My project structure includes the following:
backend/
- This is a Python Flask app that runs on port 5000 and uses SQLite.processor/
- This is a Node.js service that has anapp.js
file to handle queue processing, communicates through a JSON API on port8080
, utilizes Redis for caching, and saves files in theprocessor/assets/
directory.
This question is specifically about the processor
service.
processor/Dockerfile:
FROM node:10
WORKDIR /app
COPY package.json /app/
RUN npm install
COPY . /app/
docker-compose.yml:
redis:
image: redis
processor:
build: ./processor
command: npm run dev
ports:
- "8080:8080"
volumes:
- ./processor/:/app/
links:
- redis
Upon running docker-compose build
, everything works as it should and all dependencies are installed in /app/node_modules
as expected. I can confirm this as I see the installation output:
npm WARN package.json [email protected] No description
> [email protected] install /app/node_modules/html-pdf/node_modules/puppeteer
> node install.js
<output continues>
However, when I run docker-compose up
, I encounter a module error:
processor_1 | Error: Cannot find module 'lodash'
processor_1 | at Function.Module._resolveFilename (module.js:548:15)
processor_1 | at Function.Module._load (module.js:475:25)
processor_1 | at Module.require (module.js:597:17)
processor_1 | at require (module.js:613:17)
processor_1 | at Object.<anonymous> (/app/app.js:2:18)
processor_1 | at Module._compile (module.js:649:30)
processor_1 | at Object.Module._extensions..js (module.js:660:10)
processor_1 | at Module.load (module.js:565:32)
processor_1 | at tryModuleLoad (module.js:505:12)
processor_1 | at Function.Module._load (module.js:497:3)
It appears that the /app/node_modules
folder is completely empty in both the Docker container and on the host machine.
When I run npm install
on my host device manually, everything then works well. However, I would prefer that Docker handle all dependencies without requiring me to perform local installations.
What could be causing this issue? All necessary packages are accurately listed in my package.json
file.