Reputation: 14290
I am new to docker and I have created my custom image.
Here are my Dockerfile
FROM node:latest
MAINTAINER FF
COPY . /var/www
WORKDIR /var/www
RUN npm install
EXPOSE 3000
ENTRYPOINT ["npm", "start"]
I then build an image with
docker build -t test/node .
After the image is built, I ran
docker run -p 8888:3000 -v $(pwd):/var/www -w "/var/www" test/node
I use -v because I wanted to mount my host src folder to the /var/www
.
It came back as
> [email protected] start /var/www
> node ./bin/www
module.js:472
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/www/app.js:1:77)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
npm info lifecycle [email protected]~start: Failed to exec start script
npm ERR! Linux 4.4.39-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v7.4.0
npm ERR! npm v4.0.5
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script 'node ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the expresssite package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs expresssite
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls expresssite
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! Please include the following file with any support request:
npm ERR! /var/www/npm-debug.log
I think the issue is my src folder doesn't have express module but I already did npm install in my image and I thought that's all I need.
What did I do wrong? Can anyone help me about it? Thanks so much!
Upvotes: 2
Views: 1465
Reputation: 265080
You created an image where you ran the npm install on the /var/www folder, inside the image. This install did not happen on your host filesystem.
Then you used that image to spin up a container and mounted your host filesystem to /var/www. That overlays everything that exists at that location in the image, so prior installs you've done at that location are not visible unless you've run them on your host.
Your options include:
Upvotes: 2
Reputation: 426
The problem is the combination of COPY and volume
What's happening
What you want to do is run npm install either before starting docker or inside it.
Upvotes: 2