Docker image running have getaddrinfo eai_again maps.googleapis.com:443
See original GitHub issueIm using the Express generator to generate the pug view Im using the npm 5.4.2 and nodejs 6.x Im using the npm start my app without any problem but when I build this app into a docker image, and then run it. It comes out the problem like dns problem.
function createGoogleOptions(query){
var options = {
hostname: 'maps.googleapis.com',
port: 443,
path: '/maps/api/geocode/json?',
method: 'GET'
};
var str = 'address=' + query +'&key=' + 'AIzaSyA9wNCIiINgXZITnyP1p3MGMWTdaWpJtMk';
options.path += str;
console.log(options.path);
return options;
}
var express = require('express');
var router = express.Router();
const request =require('request');
var https = require('https');
var http = require('http');
/* GET home page. */
router.get('/', function(appReq, appRes, next) {
console.log(appReq.url);
console.log(appReq.path);
console.log(appReq.query.location);
function createGoogleOptions(query){
var options = {
hostname: 'maps.googleapis.com',
port: 443,
path: '/maps/api/geocode/json?',
method: 'GET'
};
var str = 'address=' + query +'&key=' + 'AIzaSyA9wNCIiINgXZITnyP1p3MGMWTdaWpJtMk';
options.path += str;
console.log(options.path);
return options;
}
function createYelpOptions(term,lat, lng){
var options = {
hostname: 'api.yelp.com',
port: 443,
path: '/v3/businesses/search?',
method: 'GET',
headers: {
'Authorization' : 'Bearer lTy6fRnbm063oo_X3itFala7Y5yb6DS8wIlX_oteHqDr0xn5yHNwXCXu14cLMKj6WobnGVCOSMSNQIvXxRyvdkwYRwu3BKEP13GbiQCWcOCm72C3jf2ee8tkvy3GWXYx'
//'user-key' : 'eefc2a80e3a6ccdee95930f59d476b56'
}
};
term= 'hotel';
var str = 'term='+ term + '&latitude=' + lat + '&longitude=' + lng ;
options.path += str;
console.log(options.path);
return options;
}
var query = appReq.query.location.replace(/ /g, "+");
var options = createGoogleOptions(query);
var googleReq = https.request(options, function(googleRes){
var body = [];
googleRes.on('data', function(chunk){
body.push(chunk);
});
googleRes.on('end', function(){
var bodyString = body.join("");
var geoRsp = JSON.parse(bodyString);
console.log("Google result : " + geoRsp.status);
if(geoRsp.status == "OK"){
var location_result = geoRsp.results[0].geometry.location;
console.log("Geolocation API response" + appReq.query.location);
console.log("Lat : " + location_result.lat + " Lng : " + location_result.lng);
var yelpOptions = createYelpOptions('hotel',location_result.lat,location_result.lng);
var yelpReq = https.request(yelpOptions, function(yelpRes){
console.log('headers: ', yelpRes.headers);
console.log('statusCode: ', yelpRes.statusCode);
var body = '';
yelpRes.on('data',function(chunk) {
body += chunk;
});
yelpRes.on('end', function() {
var yelpRsp = JSON.parse(body);
console.log("Result found :" + yelpRsp.total);
appRes.setHeader("content-type","text/html");
appRes.setHeader("Access-Control-Allow-Origin", "*");
appRes.render('hotel',{yelpRsp});
appRes.end();
});
});
yelpReq.on('error', (e) => {
console.error(e);
});
yelpReq.end();
} else {
console.log("Result not found !!!!");
appRes.setHeader("Content-Type", "text/html");
appRes.setHeader("Access-Control-Allow-Origin", "*");
var hotelResult = {'totalHotelCount' : 0
};
appRes.render('index',{});
appRes.end();
}
});
});
googleReq.on('error', (e) => {
console.error(e);
});
googleReq.end();
});
module.exports = router;
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
What's the cause of the error 'getaddrinfo EAI_AGAIN'?
If you get this error from within a docker container, e.g. when running npm install inside of an alpine container, the cause could...
Read more >How to fix nodejs DNS issues? - Medium
While working on big node eCOM backend that had a lot of traffic, from time to time we found getaddrinfo EAI_AGAIN error in...
Read more >eai_again - You.com | The AI Search Engine You Control
You.com is an ad-free, private search engine that you control. Customize search results with 150 apps alongside web results. Access a zero-trace private ......
Read more >Container runtime contract | Cloud Run Documentation
This page lists key requirements and behaviors of containers in Cloud Run. There are a few differences between Cloud Run services and Cloud...
Read more >azure devops - Deployment Error: getaddrinfo ENOTFOUND ...
The official solution is documented here: MS Docs: Create ILB ASE - DNS Configuration. You need to have DNS entries for your ASE...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Restarted docker - solved it for me.
@MartinMuzatko answer solved this issue when you have variable names for mapping url to ip best to give docker a restart and then it should be able to resolve them . sudo systemctl restart docker