I am trying use below dockerfile to create an image for my angular application but its failing at npm install.
FROM node:12.7-alpine AS build
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build
### STAGE 2: Run ###
COPY --from=build /usr/src/app/dist/pdpb /usr/share/nginx/html
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 :
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
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 :
Run your DNS server on a little less private IP (192.168.*.* or 10.*.*.* would work fine) and configure your host using that IP
Add this line to your Dockerfile :
RUN echo 'nameserver 18.104.22.168'>/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