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