8

I am new to docker and for my learning purpose I followed the official nodejs docker instructons and followed the instructions but it keeps throwing error on the same command.

Tried Reinstalling the whole docker as mentioned in the Official repository installation for Ubuntu 18.04 Bionic beaver for arch amd64 64 bit but still getting the same error.

(sudo permissions has already been granted to npm and docker. Running docker and npm without sudo * running npm install works fine using in the terminal

Dockerfile

FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]

ERROR

Sending build context to Docker daemon  19.46kB
Step 1/7 : FROM node:8
---> 55791187f71c
Step 2/7 : WORKDIR /usr/src/app
---> Using cache
---> 440112b72584
Step 3/7 : COPY package*.json ./
---> Using cache
---> 956513348aa7
Step 4/7 : RUN npm install
---> Running in dbbf0bc0d749
npm WARN hello@1.0.0 No repository field.

npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/array-flatten/-/array- 
flatten-1.1.1.tgz failed, reason: getaddrinfo EAI_AGAIN 
registry.npmjs.org:443

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-08-27T20_59_09_800Z-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 1

Docker version and info

Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:24:51 2018
 OS/Arch:           linux/amd64
 Experimental:      false
Server:
 Engine:
 Version:          18.06.1-ce
 API version:      1.38 (minimum version 1.12)
 Go version:       go1.10.3
 Git commit:       e68fc7a
 Built:            Tue Aug 21 17:23:15 2018
 OS/Arch:          linux/amd64
 Experimental:     false
Ahsan Ahmed
  • 123
  • 1
  • 2
  • 9
  • 1
    Possible duplicate of [Error: getaddrinfo EAI\_AGAIN](https://stackoverflow.com/questions/40182121/error-getaddrinfo-eai-again) – halfer Aug 27 '18 at 21:29
  • I don't think this is Docker-specific - it is just a Node DNS/connectivity error. Are you behind a company firewall or proxy? [See this search](https://duckduckgo.com/?q=node+reason%3A+getaddrinfo+EAI_AGAIN&ia=qa). – halfer Aug 27 '18 at 21:30
  • @halfer if it would be a proxy issue then my `npm` would have the same problem running outside the `dockerfile` . currently I can run `npm` commands with ease outside the `dockerfile` via terminal – Ahsan Ahmed Aug 27 '18 at 21:45
  • 1
    I don't know that to be the case. I've not done it myself, but Docker can be [independently configured to use a proxy](https://docs.docker.com/network/proxy/). – halfer Aug 27 '18 at 21:47

5 Answers5

5

Had this error when with this line From node:alpine You may need to pull from a more recent image. I currently run node 14.x.x so I just had to pull node version 14-apline. So my first line was FROM node:14-alpine and that did the trick for me.

acha jackson
  • 81
  • 1
  • 1
3

Same problem here, apparently the COPY package*.json ./ command didn't working fine.

I solved this copying the files before install the NPM dependencies:

FROM node:8.15.1-alpine as build-stage
WORKDIR /app
COPY . .
RUN npm --verbose install
RUN npm run build
José Silva
  • 361
  • 1
  • 12
3

Just add --force in the command.

RUN npm install --force

2

I've had the same issue with my linux docker setup, when installing node-sass inside my Node.js container. It turned out that the container/ docker ran out of memory during the installation. Increasing the memory, assigned to docker, fixed the error for me.

Vincent
  • 137
  • 2
  • 15
0

In my case there was an error in package.json thats is why did not worked and threw same error.

Kumar
  • 41
  • 5