Facing issue with creating angular application image using docker

I am trying use below dockerfile to create an image for my angular application but its failing at npm install.

Dockerfile

FROM node:12.7-alpine AS build

WORKDIR /usr/src/app

COPY package.json ./

RUN npm install

COPY . .

RUN npm run build

### STAGE 2: Run ###

FROM nginx:1.17.1-alpine

COPY --from=build /usr/src/app/dist/pdpb /usr/share/nginx/html

gettiog this error.
error
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/@angular%2Fcommon failed, reason:
getaddrinfo EAI_AGAIN registry.npmjs.org

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-01-16T10_33_33_720Z-debug.log

please help me with the proper solution for this.

This look like a dns issue. Since docker forward the dns from the host to the containers, I’ld think it’s an issue with the host.
But let’s verify, on the host :

nslookup registry.npmjs.org
docker run -it --rm alpine nslookup registry.npmjs.org

Both commands should work. If both command failed, I would recommand looking into /etc/resolv.conf and fix it until the 1st command works. Once done, the second command should work, and your docker build will pass this step

getting below output for 1st command
nslookup registry.npmjs.org
Server: 127.0.1.1
Address: 127.0.1.1#53

Non-authoritative answer:
Name:	registry.npmjs.org
Address: 104.16.23.35
Name:	registry.npmjs.org
Address: 104.16.26.35
Name:	registry.npmjs.org
Address: 104.16.18.35
Name:	registry.npmjs.org
Address: 104.16.20.35
Name:	registry.npmjs.org
Address: 104.16.19.35
Name:	registry.npmjs.org
Address: 104.16.25.35
Name:	registry.npmjs.org
Address: 104.16.24.35
Name:	registry.npmjs.org
Address: 104.16.22.35
Name:	registry.npmjs.org
Address: 104.16.27.35
Name:	registry.npmjs.org
Address: 104.16.16.35
Name:	registry.npmjs.org
Address: 104.16.17.35
Name:	registry.npmjs.org

output for 2nd command

Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
e6b0cf9c0882: Already exists 
Digest: sha256:2171658620155679240babee0a7714f6509fae66898db422ad803b951257db78
Status: Downloaded newer image for alpine:latest
nslookup: can't resolve '(null)': Name does not resolve

nslookup: can't resolve 'registry.npmjs.org': Try again`Preformatted text`

One problem when developing with NPM to manage dependencies is keeping all dependencies in sync.

There is your issue.

Let me explain a little bit. You seems to be running a DNS server on your host and using it on a loopback IP (127.*.*.*). But this IP cannot be accessed from within any container (unless you specify -net host which wouldnt be desirable). So the container have DNS service available.

You have several options :
1)
Run your DNS server on a little less private IP (192.168.*.* or 10.*.*.* would work fine) and configure your host using that IP
2)
Add this line to your Dockerfile :

RUN echo 'nameserver 8.8.8.8'>/etc/resolv.conf

Before running npm. This would work around your issue allowing npm to work correctly. Yet,until you do something along the line of the 1st option, many of your containers will have the same issue

can u please tell me the 1st step how to to do that in ubuntu 16.04.

Now i am getting this issue.But is already installed in my system.

git --version
git version 2.7.4

error for my dockerfile :
npm ERR! code ENOGIT
npm ERR! No git binary found in $PATH
npm ERR!
npm ERR! Failed using git.
npm ERR! Please check if you have git installed and in your PATH.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-01-20T13_03_52_332Z-debug.log

add to your dockerfile

RUN apk add git