NPM installation error when starting Docker on CentOS

I follow this guide to pre-resize the node.js application and it always fails in the "npm install" part of the Docker file. Here is a link to the tutorial: http://docs.docker.com/examples/nodejs_web_app/

The error I am 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! < npm-@googlegroups.com > 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 have searched for several sources and I'm not sure why npm cannot find the package.json file. I also made the same setup except with the ubuntu 14.04 image, and this also does not work, but it works if I manually go into the image and start the nodejs node itself.

If anyone with more experience with docker or npm can help with this problem, that would be great.

Thanks!

+5
source share
1 answer

I had the same problem, it turned out that the Docker tutorial is a bit ambiguous and makes it easy to corrupt 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 

COPY . /src team COPY . /src COPY . /src leads to the following tree in the Docker image:

 /src/Dockerfile /src/src/package.json /src/src/index.js 

So put package.json and index.js in the same folder as your Docker file, and it should work fine.


One more thing, when debugging a failed build like this, you can use the image identifier to look into the directory tree, even if the container is not running. For example, given the following output from docker build :

 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 check the / src directory and see what went wrong. Alternatively, use /bin/bash instead of ls -lR /src to get a shell and pop.

+3
source

Source: https://habr.com/ru/post/1210685/


All Articles