Repository navigation
npm install and other http requests fail with getaddrinfo ENOENT in a Windows Docker container #2578
Description
I try to run io.js 3.2.0 inside a Windows Docker container within the Windows 2016 Technical Preview 3.
I encounter problems running npm install inside such a container (for a Windows version of the iojs:onbuild Dockerfile) and now I've reduced the problem to a simpler test code.
An http.get() (or https.get()) request fails inside the container with the error Error: getaddrinfo ENOENT
C:\app>node httpsrequest.js
events.js:141
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOENT registry.npmjs.org:443
at Object.exports._errnoException (util.js:837:11)
at errnoException (dns.js:30:15)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
C:\app>node httprequest.js
events.js:141
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOENT registry.npmjs.org:80
at Object.exports._errnoException (util.js:837:11)
at errnoException (dns.js:30:15)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
The httprequest.js test code looks like this:
'use strict';
var http = require('http');
http.get({
host: 'registry.npmjs.org',
path: '/'
}, function(response) {
// Continuously update stream with data
var body = '';
response.on('data', function(d) {
body += d;
});
response.on('end', function() {
var parsed = JSON.parse(body);
console.log('body', parsed);
});
});But using the dns module to try the lookup manually works within the same Docker container:
C:\app>node dnstest.js
dns.lookup ...
dns.lookup callback
185.31.17.162
null
dns.resolve ...
dns.resolve callback
[ '185.31.17.162' ]
null
And the dnstest.js test code used is this:
var dataDomain = 'registry.npmjs.org',
dns = require("dns");
console.log('dns.lookup ...');
dns.lookup(dataDomain, function(error, addr){
console.log('dns.lookup callback');
console.log(addr);
console.log(error);
console.log('dns.resolve ...');
dns.resolve(dataDomain, function(error, addr){
console.log('dns.resolve callback');
console.log(addr);
console.log(error);
});
});Any ideas why such lookup inside http.get() fails, but dns.lookup() works fine?
This makes it hard to use Node.js/io.js inside a container at the moment.
The ipconfig /all inside the container shows this:
C:\app>ipconfig /all
Windows IP Configuration
Host Name . . . . . . . . . . . . : vagrant-2016
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : localdomain
Ethernet adapter vEthernet (Virtual Switch-70915fd03979c911c8fb0ec47991ce77edb326d5b0e7696d9ab1bd7f235fdd25-0):
Connection-specific DNS Suffix . : localdomain
Description . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter #3
Physical Address. . . . . . . . . : 00-15-5D-00-00-01
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::851d:8eb3:494c:cd%20(Preferred)
IPv4 Address. . . . . . . . . . . : 172.16.0.2(Preferred)
Subnet Mask . . . . . . . . . . . : 255.240.0.0
Default Gateway . . . . . . . . . : 172.16.0.1
DNS Servers . . . . . . . . . . . : 192.168.254.2
NetBIOS over Tcpip. . . . . . . . : Disabled
PS: I also tried a little GO binary inside the container which does pretty the same and that works fine within the Windows Docker container:
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
)
func main() {
response, err := http.Get("http://registry.npmjs.org/")
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
fmt.Printf("%s\n", string(contents))
}
}C:\app>httprequest-go.exe
{"db_name":"registry","doc_count":195018,"doc_del_count":363,"update_seq":1278195,"purge_seq":0,"compact_running":false,"disk_size":5170360452,"data_size":702746874,"instance_start_time":"1435359693255822","disk_format_version":6,"committed_update_seq":1278195}
Activity
StefanScherer commentedon Aug 27, 2015
Some more details to build the
iojsandiojs:onbuildDocker Containers for Windows can be found in this small blog post.ChALkeR commentedon Aug 27, 2015
Try this:
I assume that it would fail. Could you confirm that?
StefanScherer commentedon Aug 27, 2015
Thanks @ChALkeR!
Yes, this indeed fails:
ChALkeR commentedon Aug 27, 2015
Thanks for confirming.
httpcallsnet.connect, and that's how it resolves an address here: lib/net.js#L907-L989.StefanScherer commentedon Aug 27, 2015
Thanks for the pointer.
Changing the
hintsto0it works:ChALkeR commentedon Aug 27, 2015
So, if I got it right:
dns.lookup(addr, callback)works, butdns.lookup(addr, {family: undefined, hints: dns.ADDRCONFIG | dns.V4MAPPED}, callback)doesn't.Could you please check the following:
dns.lookup(addr, {hints: dns.ADDRCONFIG | dns.V4MAPPED}, callback)— does not work as tested above,dns.lookup(addr, {hints: dns.ADDRCONFIG}, callback),dns.lookup(addr, {hints: dns.V4MAPPED}, callback),dns.lookup(addr, {hints: 0}, callback)— works as tested above.StefanScherer commentedon Aug 27, 2015
OK, all combinations.
My test code
dns3.js:running this in the Windows container show this:
Seems that the
dns.ADDRCONFIGcauses the trouble.ChALkeR commentedon Aug 27, 2015
Thanks. Looks like
dns.ADDRCONFIGmakes dns lookup queries fail on your system.Still, according to your
ipconfig /all, your system has an non-loopback IPv4 address, so the lookup shouldn't ignore IPv4 results (see api docs and msdn for details).The final check here would be to test
getaddrinfo()function with AI_ADDRCONFIG hint, but without io.js/node, just with a simple native program.If you want a workaround, supplying your own lookup function via
optionscould work.Monkey-patching
dns.lookupordns.ADDRCONFIGor evennet.Socket.prototype.connectcould also work as a temporary workaround, but I wouldn't recommend doing that.StefanScherer commentedon Aug 27, 2015
I originally tried to run
npm installor other 3rd party node apps/modules inside the Windows container.The
npm installends up with an error:So I think I should ask someone of the Microsoft team that is currently porting Docker on Windows.
ChALkeR commentedon Aug 27, 2015
@StefanScherer I updated my previous comment, please re-read it =).
If that fails, this is most likely a Windows/Docker related problem, If it succeeds (which I doubt), then further investigation is needed on the io.js/node side.
StefanScherer commentedon Aug 27, 2015
@ChALkeR thanks so far to get to the underlying problem. I try to build a simple Windows C application based on the example code in the msdn reference.
7 remaining items
StefanScherer commentedon Apr 21, 2016
@seanlarge I can confirm that.
At the moment I use this workaround in my node 5.10.1 Windows Dockerfile.
I watch the progress in moby/moby#15889 as well, there is an internal issue open at Microsoft to address this. Let's see what TP5 will do for us.
sudosean commentedon Apr 21, 2016
@StefanScherer thank you for the quick reply...does FROM micorsoft/node not work? here is my dockerfile (I have also had a huge problem with 'invalid directories', do I need to change my WORKDIR to have quotes?):
StefanScherer commentedon Apr 21, 2016
@seanlarge The
microsoft/nodeDocker image works with the patch, I've used it in the Docker Birthday App and ported the Dockerfile to Windows.sudosean commentedon Apr 21, 2016
@StefanScherer Thank you so much! I will keep an eye on the open issues.
sudosean commentedon Apr 21, 2016
@StefanScherer I end up with the following error:
sudosean commentedon Apr 21, 2016
@StefanScherer my dockerfile:
StefanScherer commentedon Apr 22, 2016
@seanlarge That's another problem of TP4. The network stack is not always up when the RUN command is already running.
This is a workaround for TP4, in TP5 the sleep is no longer needed:
PS: Perhaps I forgot the
powershell -Commandin my comments above.sudosean commentedon Apr 22, 2016
@StefanScherer still the same issue =( not sure what to do.
result:
dockerfile:
sudosean commentedon Apr 22, 2016
same thing with docker file from https://github.com/StefanScherer/dockerfiles-windows/blob/776120fb5b24c68e73243eb74b440eb4f2c24059/node/5.9/Dockerfile#L13-L15
I tired FROM windowsservercore instead of microsoft/node, same result.
@StefanScherer the problem is that there is no network connection?
juddybuddy77 commentedon Apr 24, 2016
Same issue here.
Tried applying the patch manually, no problem there, still can't get NPM to work in the container. Unfortunately don't know enough to attempt to patch myself, so I'll site back quietly and watch for now. Thanks for posting this.
Woah, moving too fast there, not sure why running the patch failed the first time, this time got the message it was updating hints, after fixing the npm registry it worked. Thank you!
StefanScherer commentedon Apr 27, 2016
It seems that is fixed in TP5. Got
npm installworking inside a windowsservercore container without a patched node.exe.binarymist commentedon Apr 18, 2018
If using Docker, this known issue is discussed in detail here: https://development.robinwinslow.uk/2016/06/23/fix-docker-networking-dns/
Simple fix is to create the file
/etc/docker/daemon.jsonand insert:
where
10.0.0.2is the first DNS server your machine requests records from, and8.8.8.8is the fallback DNS server, google in this case.grantwparks commentedon Dec 22, 2018
binarymist - Where's the /etc dir on Windows?
binarymist commentedon Dec 22, 2018
%systemroot%\system32\drivers\etcUsually:
C:\Windows\System32\drivers\etcI'm thinking
PS: It's usually quicker and easier to ask a search engine these types of generic questions.
grantwparks commentedon Dec 22, 2018
I'm just trying to point out that a linux answer is not relevant.