Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker npm install Error: getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443

Tags:

node.js

docker

I'm using docker version 1.10.1 on RHEL 7 and getting npm install error when using below Dockerfile. The Error: getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443. The same work with docker 1.91 on ubuntu 14.04. When I get bash and install inetutils-ping on container I noticed I can't ping anywhere

root@9deb4b274c1e:/home/nodexp#ping 8.8.8.8           
PING 8.8.8.8 (8.8.8.8): 56 data bytes
^C--- 8.8.8.8 ping statistics ---
4 packets transmitted, 0 packets received, 100% packet loss

Why is that ? Of course I can ping from RHEL

Dockerfile

FROM node:argon
# Create user nodexp in group nodexp
RUN groupadd -r nodexp \
    && useradd -m -r -g nodexp nodexp
WORKDIR /home/nodexp
# Install app dependencies
COPY package.json /home/nodexp
RUN npm install
# Bundle app source
COPY . /home/nodexp
EXPOSE 3000
CMD [ "npm", "start" ]

and package.json

{
  "name": "mp",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node app.js"
  },
  "dependencies": {
    "express": "~4.13.1"

  }
}
like image 363
irom Avatar asked Feb 19 '16 21:02

irom


People also ask

Where can I find the NPM err Debug log?

A complete log of this run can be found in: npm ERR! /home/lefteris/.npm/_logs/2017-12-26T09_30_35_700Z-debug.log The debug log is here. I also tried to set the registry to the non-https version but still had the same problem. How can the CLI team reproduce the problem?

What is the server name of the npmjs registry?

nslookup registry.npmjs.org Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: registry.npmjs.org canonical name = a.sni.fastly.net. Name: a.sni.fastly.net Address: 151.101.12.162

Why can't I access NPM on my company network?

In any case, you should ask someone in your company about it because most likely you either need to use a specific proxy or someone needs to lift the restriction from your npm and allow it to access the network. The network access can be blocked by a firewall installed on your computer or a router in your network.

How to fix Ping/curl is not working with npm install?

If you are able to ping/curl to npm registry but still getting error with npm install, the error might likely be due to missing ca-certs package. Add the following line to Dockerfile before npm install and re-build the image.


1 Answers

I fix this problem based on this article https://development.robinwinslow.uk/2016/06/23/fix-docker-networking-dns

actually, you could check the DNS if it fails or not while calling registry.npmjs.org

To check that thing, I did these steps to make it work

Step 1

Run this command on busybox image, I will use google.com to simulate the connection request

>> docker run busybox nslookup google.com 
   Unable to find image 'busybox:latest' locally
   latest: Pulling from library/busybox
   f70adabe43c0: Pull complete 
   Digest: sha256:58ac43b2cc92c687a32c8be6278e50a063579655fe3090125dcb2af0ff9e1a64
   Status: Downloaded newer image for busybox:latest
   nslookup: can't resolve 'google.com'
   Server:    8.8.8.8
   Address 1: 8.8.8.8

Step 2

As you can see from step 1 result, I got an error and cannot resolve connection to google.com, if you got a similar error then do this to check your current DNS route.

 >> nmcli dev show | grep 'IP4.DNS' 
    IP4.DNS[1]:                             192.168.2.1

That command exposes your IP4 DNS which in this case 192.168.2.1, on this step you already know the DNS.

Step 3

Let's continue using busybox container to connect using this DNS by running

 >> docker run --dns 192.168.2.1 busybox nslookup google.com
    Server:    192.168.2.1
    Address 1: 192.168.2.1 giftcard.dyndns.org

    Name:      google.com
    Address 1: 2404:6800:4003:c03::65
    ....

Step 4

If your result is similar like on step 3, then your problem is docker couldn't connect because docker doesn't know the DNS will be used on, so we fix that by making daemon.json file and locate that in /etc/docker/daemon.json. these the content to put.

{
  "dns": ["192.168.2.1", "8.8.8.8"] // 192.168.2.1 is value of your dns
}

Step 5

Restart your docker service

>> sudo service docker restart
like image 155
Aditya Kresna Permana Avatar answered Oct 29 '22 10:10

Aditya Kresna Permana