Docker can't install npm packages

Viewed 11771

I'am running docker on ubuntu server.

It seems to be a docker problem. Installing the package.json from ubuntu works fine.

npm http request GET https://registry.npmjs.org/express
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443

It seems the npm registry is not reachable. Any ideas?

Ping works fine!

Dockerfile:

FROM node:4-slim

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app/

RUN npm install

COPY . /usr/src/app

EXPOSE 3000

CMD [ "node", "server.js" ]

Build-Log:

Sending build context to Docker daemon  66.05kB
Step 1/8 : FROM node:4-slim
 ---> cd692e27dc7f
Step 2/8 : RUN mkdir -p /usr/src/app
 ---> Running in 876d5978bdd7
 ---> 4bab541344aa
Removing intermediate container 876d5978bdd7
Step 3/8 : WORKDIR /usr/src/app
 ---> d66516529b5e
Removing intermediate container 6317ee72e20e
Step 4/8 : COPY package.json /usr/src/app/
 ---> 70483f422380
Removing intermediate container c3781f622ce4
Step 5/8 : RUN npm install
 ---> Running in 37d8afdf1c21
npm info it worked if it ends with ok
npm info using npm@2.15.11
npm info using node@v4.8.3
npm WARN package.json docker-node-test@1.0.0 No description
npm WARN package.json docker-node-test@1.0.0 No repository field.
npm WARN package.json docker-node-test@1.0.0 No README data
npm info preinstall docker-node-test@1.0.0
npm info attempt registry request try #1 at 10:58:13 AM
npm http request GET https://registry.npmjs.org/express
npm info attempt registry request try #1 at 10:58:13 AM
npm http request GET https://registry.npmjs.org/mongoose
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm info attempt registry request try #2 at 10:59:04 AM
npm http request GET https://registry.npmjs.org/mongoose
npm info attempt registry request try #2 at 10:59:04 AM
npm http request GET https://registry.npmjs.org/express
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm info attempt registry request try #3 at 11:00:44 AM
npm http request GET https://registry.npmjs.org/mongoose
npm info attempt registry request try #3 at 11:00:44 AM
npm http request GET https://registry.npmjs.org/express
npm ERR! Linux 4.4.0-78-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.8.3
npm ERR! npm  v2.15.11
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! syscall getaddrinfo

npm ERR! getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /usr/src/app/npm-debug.log
5 Answers

This is also an issue I was encountering on Docker for Windows and the GitLab Windows runner. The issue was with docker run the network works correctly and was able to ping/resolve all domains. When running docker build npm would fail with the EAI_AGAIN error.

Resolution

docker build has the --network=available for Docker build docs

Find the working Docker network you are using for your docker run or docker-compose project.

  • lookup docker network: docker network ls
  • Run Docker build using the network from above docker build --network=<insert network from above> -f "myproj\Dockerfile" -t app:latest

It's a connection issue In my case docker restart solve problem

service docker restart

I'm also facing a similar issue here, in one of the solutions mentioned above, it says to check the available networks using

docker network ls

in my case, it returned

NETWORK ID     NAME      DRIVER    SCOPE
2e21805e212e   bridge    bridge    local
034ff467139e   host      host      local
ac0222d91002   none      null      local

tried using all three of these, as

sudo docker build --network=034ff467139e -t getting-started ./

exactly the same issue remains, also tried restarting the docker service, did not work either

edit: the issue seems to be that this command expects the "Name" of the network as the value rather than the "Network Id" running it like this solved the problem in my case,

docker build --network=host -t getting-started
Related