I'm following this tutorial to dockerize a node.js app and it always fails at the 'npm install' part in the Dockerfile. Here is the link to the tutorial: http://docs.docker.com/examples/nodejs_web_app/
The error I'm getting is shown below:
npm ERR! install Couldn't read dependencies
npm ERR! Error: ENOENT, open '/src/package.json'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR! System Linux 3.13.0-43-generic
npm ERR! command "node" "/usr/bin/npm" "install"
npm ERR! cwd /src
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.3.6
npm ERR! path /src/package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /src/npm-debug.log
npm ERR! not ok code 0
I've searched multiple sources and I'm not sure why npm can't find the 'package.json' file. I've also done the same setup except with an ubuntu 14.04 image and that doesn't work either, but it works if I manually go into the image and start the nodejs server myself.
If anybody with more experience with docker or npm could help out on this issue that'd be great.
Thanks!
I was having this same problem, turns out the Docker tutorial is a bit ambiguous and makes it easy to screw up the directory tree if you don't understand the behavior of COPY.
I had this directory tree:
workdir/Dockerfile
workdir/src/package.json
workdir/src/index.js
The command COPY . /src
results in the following tree in the Docker image:
/src/Dockerfile
/src/src/package.json
/src/src/index.js
So basically, put package.json
and index.js
in the same folder as your Dockerfile and it should work fine.
One other thing, when debugging a failed build like this, you can use the image ID to have a peek at the directory tree even if the container isn't running. For example, given the following docker build
output:
Step 4: RUN cd /src; npm install
---> Running in 4bce6ad89dab
---> 3084f3523d93
ERROR! BAD THINGS! PANIC!
The image ID in this case is 3084f3523d93
, so you can run docker run --rm 3084f3523d93 ls -lR /src
to inspect the /src directory and see what went wrong. Alternatively, use /bin/bash
in place of ls -lR /src
to get a shell and poke around.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With