我正在ubuntu服务器上运行docker。
这似乎是一个码头工人问题。从ubuntu安装package.json工作正常。
npm http request GET https://registry.npmjs.org/express
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
似乎无法访问npm注册表。有什么想法吗?
Ping工作正常!
Dockerfile:
FROM node:4-slim
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
EXPOSE 3000
CMD [ "node", "server.js" ]
构建-日志:
Sending build context to Docker daemon 66.05kB
Step 1/8 : FROM node:4-slim
---> cd692e27dc7f
Step 2/8 : RUN mkdir -p /usr/src/app
---> Running in 876d5978bdd7
---> 4bab541344aa
Removing intermediate container 876d5978bdd7
Step 3/8 : WORKDIR /usr/src/app
---> d66516529b5e
Removing intermediate container 6317ee72e20e
Step 4/8 : COPY package.json /usr/src/app/
---> 70483f422380
Removing intermediate container c3781f622ce4
Step 5/8 : RUN npm install
---> Running in 37d8afdf1c21
npm info it worked if it ends with ok
npm info using npm@2.15.11
npm info using node@v4.8.3
npm WARN package.json docker-node-test@1.0.0 No description
npm WARN package.json docker-node-test@1.0.0 No repository field.
npm WARN package.json docker-node-test@1.0.0 No README data
npm info preinstall docker-node-test@1.0.0
npm info attempt registry request try #1 at 10:58:13 AM
npm http request GET https://registry.npmjs.org/express
npm info attempt registry request try #1 at 10:58:13 AM
npm http request GET https://registry.npmjs.org/mongoose
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm info attempt registry request try #2 at 10:59:04 AM
npm http request GET https://registry.npmjs.org/mongoose
npm info attempt registry request try #2 at 10:59:04 AM
npm http request GET https://registry.npmjs.org/express
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm info attempt registry request try #3 at 11:00:44 AM
npm http request GET https://registry.npmjs.org/mongoose
npm info attempt registry request try #3 at 11:00:44 AM
npm http request GET https://registry.npmjs.org/express
npm ERR! Linux 4.4.0-78-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.8.3
npm ERR! npm v2.15.11
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! syscall getaddrinfo
npm ERR! getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /usr/src/app/npm-debug.log
答案 0 :(得分:1)
这是一个连接问题,与你的代码无关,Dockerfile很好。
这可能是一个间歇性的连接问题,或者可能是网络防火墙限制,或者其他一些疯狂的IP疯狂事件。
我看到很多间歇性的连接问题,运行各种工具来从互联网上打包东西,有时它只是其中之一。
在上次尝试使用的网络上的计算机上试用。
答案 1 :(得分:1)
这是一个网络配置问题更可能是iptables ...你设置了docker0自定义范围吗?看看那里。
答案 2 :(得分:0)
这也是我在Windows版Docker和GitLab Windows运行器上遇到的问题。问题出在docker run
上,网络可以正常工作并且能够ping /解析所有域。运行docker build
时,npm会失败,并显示EAI_AGAIN错误。
解决方案
docker build
具有--network=
可用于Docker build docs
找到用于docker run或docker-compose项目的可用Docker网络。
docker network ls
docker build --network=<insert network from above> -f "myproj\Dockerfile" -t app:latest
上方的网络运行Docker构建