这是一个dockerfile
FROM node:alpine
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
CMD ["npm","start"]
当我运行docker build .
时,我得到了
Sending build context to Docker daemon 4.096kB
Step 1/6 : FROM node:alpine
---> 72ca8e2f26fa
Step 2/6 : WORKDIR '/app'
---> Using cache
---> 39c33c7a6b1c
Step 3/6 : COPY package.json .
---> Using cache
---> 79a79ca26be1
Step 4/6 : RUN npm install
---> Running in 45e16e475139
npm ERR! code EAI_AGAIN
npm ERR! syscall getaddrinfo
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/express 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/2021-05-27T22_06_22_293Z-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 1
我该怎么解决?
附言:请注意,我正在使用ubuntu 20.04,我对使用docker非常陌生。
编辑
这是index.js文件:
const express = require('express');
const redis = require('redis');
const app = express();
const client = redis.createClient();
client.set('visits', 0);
app.get('/', (req, res) => {
client.get('visits', (err, visits) => {
res.send('Number of visits ' + visits);
client.set('visits', parseInt(visits) + 1);
});
});
app.listen(8081, () => {
console.log('listening on port 8081');
});
这是package.json文件:
{
"dependencies": {
"express": "*",
"redis": "2.8.0"
},
"scripts": {
"start": "node index.js"
}
}
我认为我在代码或包中没有任何错误。
EAI_AGAIN意味着DNS服务器回复说它当前无法完成请求。
如果您在Firebase Cloud Functions中遇到此错误,这是由于免费层的限制(仅允许Google服务使用出站网络(。
升级到火焰或火焰计划使其工作。