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
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
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
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