I’ve recently ran into this issue when setting up a XM Cloud development environment locally:
“Could not resolve host: nodejs.org”
The command 'cmd /S /C curl.exe -sS -L -o node.zip https://nodejs.org/dist/vdo/node-v%NODEJS_VERSION%-win-x64.zip' returned a non-zero code: 6
This happens when the docker container cannot resolve DNS due to a network issue. To test connectivity from inside a container, run:
docker run -it mcr.microsoft.com/windows/servercore:ltsc2019 powershell
invoke-webrequest -uri https://nodej.org -useBasicParsing
Possible solutions
There are different reasons why Docker might not be able to resolve DNS:
A) Windows Firewall Issue
Try disabling Windows Firewall and test again.
B) Docker using wrong network interface
Docker seems to always use the network interface with the lowest InterfaceMetric.
Run this powershell command on your computer to list interfaces:
Get-NetIPInterface -AddressFamily IPv4 | Sort-Object -Property InterfaceMetric -Descending
In my case, I was on Wi-Fi, Ethernet was disconnected, but docker tried to use the Ethernet interface. I needed to set the interface metric specifically:
Set-NetIPInterface -InterfaceAlias 'your interface alias' -InterfaceMetric 3
C) VPN Client blocking docker networks
Some VPN clients block docker’s virtual networks preventing DNS from working in docker containers. Resort to your individual VPN client configuration.