DNS broken on Docker Desktop for windows

Trying to resolve DNS names in docker windows (windows containers) appears broken by default and with no easy way to resolve. There are dozens of posts about this, but few with fixes (and none of those have enough details or actually work).

  • To reproduce

    • install docker windows desktop
    • switch to windows container mode
    • docker  run -it mcr.microsoft.com/windows/servercore:ltsc2022 powershell
      
      inside container, run
      ping www.google.com
      
      and it fails to resolve the name
      • Then repeat above, adding –dns 8.8.8.8 to docker run line and it all works
  • So issue is just the default DNS stuff not working with docker. You CAN workaround some issues by just specifying --dns on the command line. But not all (like docker build scripts) or scripts that indirectly use docker.

{
  "dns": [
    "8.8.8.8"
  ],
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": false,
  "features": {
    "buildkit": true
  }
}

But sadly this doesnt seem to work (appears totally ignored).

1 Like

One more hint - I’ve found another workaround, and it maybe relevant to understanding the bug.

Specifying --network “Default Switch” command line argument to docker run also avoids the problem, so maybe there is some mistake in the default understanding / configuration for networking, but there is no UI to correct it in the current version of Docker desktop (despite screenshots of a network settings page in other docker questions on the web).

True. With my version 4.20.1 of Docker Desktop I have the same issue. I need to deliberately create a network (docker network create mynetwork) and then add the --network mynetwork to the docker run command in order for the dns to resolve. That is very odd, that the networks are not set to be the same by default. I don’t see the reasoning behind it - using docker desktop. (I understand for enterprise-graded container runtimes/orchestrations)

Im having a similar issue with DockerDesktop v4.22.1.

Im using vscode’s devcontainers on windows 11. Once it starts up in the container and i open a bash terminal tab…can ping www.google.com fine. However if I cd into another directory, strangely i can no longer do so and error from the ping command is ‘temporary failure in name resolution’.

Any thoughts on how to diagnose what is happening here?

Does this help.