Docker : Hyper-V was unable to find a virtual switch with name "DockerNAT"
Asked Answered
L

9

5

I updated my docker for desktop app (Version 2.0.0.3) on Windows 10 pro.But since then my docker is not starting and throwing following error.

Hyper-V\Get-VMNetworkAdapter : Hyper-V was unable to find a virtual switch with name "DockerNAT".
At C:\Program Files\Docker\Docker\resources\MobyLinux.ps1:121 char:25
+ ... etAdapter = Hyper-V\Get-VMNetworkAdapter -ManagementOS -SwitchName $S ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (DockerNAT:String) [Get-VMNetworkAdapter], VirtualizationException
    + FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.GetVMNetworkAdapter

I followed the steps mentioned in the link (Docker on windows 10 can't startup after deleting MobyLinuxVM in Hyper-V manually ) , but it did not fix the issue. enter image description here I have also tried disabling --> restarting --> and then enabling Hyper V and containers option using "Turn windows feature on or off" present at "Control Panel\Programs\Programs and Features"

My network connection has following information enter image description here

But still I am not being able to start my windows Docker app, which keeps throwing

Hyper-V was unable to find a virtual switch with name "DockerNAT".
at New-Switch, <No file>: line 121
at <ScriptBlock>, <No file>: line 411
Leviathan answered 19/2, 2019 at 9:18 Comment(0)
I
3

I also faced this issue once.

I tried several workarounds but nothing worked. The issue was that the MobyLinuxVM could not create the Docker NAT switch, as a result Docker service could not be started.

The working solution was to reset my network settings. I cannot remember if I had to remove all network related entries in Computer Management in order to be re-initialized from scratch.

Important: You will lose all user defined network-related settings. Try it if everything else fails.

Edit: Another thing you can try is to restart the Hyper-V management service by executing the following commands in an admin shell:

net stop vmms
net start vmms

Found in related github issue

Irremeable answered 19/2, 2019 at 10:16 Comment(5)
Tried what you suggested i.e even removing all the network configs, still getting the same error. "Unable to create: The running command stopped because the preference variable \n "ErrorActionPreference" or common parameter is set to Stop: Hyper-V was unable to find a virtual switch with name "DockerNAT". at New-Switch, <No file>: line 121 at <ScriptBlock>, <No file>: line 411"Leviathan
Did you also delete the network adapter entries in Computer Management->Device Manager->Network Adapters?Irremeable
No, do I need to.Leviathan
@sumitkumar I have updated my answer, please give it a try if issue is still present.Irremeable
thanks @Irremeable for the new approach, but even that doesn't seem to help.Leviathan
A
1

open the hyper-v manger and check in the "Virtual switch manager" if you can see the DockerNAT there or not , Docker for windows created this switch when it starts before creating the mobylinux vm. if your powershell script is not creating this switch ten try to create it directly there .

enter image description here

Ackley answered 19/2, 2019 at 10:15 Comment(0)
S
1

I was facing the same issue after updating the docker version and got resolved by doing the following steps. Please note that i have following OS running in my machine.

Edition Windows 10 Enterprise

Version 1903

Os Build 18362.295

1:- Open "Window Security"

2:- Open "App & Browser control"

3:- Click "Exploit protection settings" at the bottom

4:- Switch to "Program settings" tab

5:- Locate "C:\WINDOWS\System32\vmcompute.exe" in the list and expand it

6:- Click "Edit"

7:- Scroll down to "Code flow guard (CFG)" and uncheck "Override system settings"

8:- Start vmcompute from powershell "net start vmcompute"

Stonehenge answered 8/9, 2019 at 12:28 Comment(0)
W
1

None of these worked for me. I have tried countless of possible solutions reported by others. In the end, this rather old post helped: https://forums.docker.com/t/latest-failed-docker-update-makes-hyper-v-unable-to-create-virtual-ethernet-switch-0x80041002/44109

So to fix the issue:

  1. uninstall crippled Docker for Windows
  2. remove both Hyper-V and Containers features then reboot
  3. add Hyper-V and Containers features back then reboot
  4. reinstall Docker for Windows then start it

Hope this helps!

Westbrooke answered 19/12, 2019 at 17:51 Comment(1)
Please note that Container is a separate feature from Hyper-V.Degeneracy
F
0

Running the MOFCOMP command and a reboot fixed this problem for me.

  1. Running this command: (Command Prompt as administrator) MOFCOMP %SYSTEMROOT%\System32\WindowsVirtualization.V2.mof

  2. Then restart

(https://community.spiceworks.com/how_to/122307-fix-error-managing-hyper-v-server-2012-r2-from-windows-10)

Fastness answered 30/5, 2019 at 12:33 Comment(0)
D
0

To solve the issue follow the steps which write in the microsoft's document below

https://support.microsoft.com/en-us/help/3101106/you-cannot-create-a-hyper-v-virtual-switch-on-64-bit-versions-of-windo

Then restart your PC.

After restarting

  1. Open Hyper-V Manager
  2. Goto Virtual Switch Manager
  3. Create new Internal virtual switch with name DockerNAT

    enter image description here

  4. Start your docker

Divine answered 4/10, 2019 at 6:58 Comment(0)
S
0

I had the same problem on windows 10 and after installing "MicrosoftEasyFix20159.mini.diagcab" my problem was solved. I think instead of creating manually a new "Internal virtual switch with name DockerNAT", installing this Microsoft Easy Fix works.

Seizure answered 25/1, 2020 at 8:26 Comment(0)
A
0

My Docker Desktop gave me a similar error

It was exactly this:

The virtual switch 'DockerNAT' cannot be deleted because it is being used by running virtual machines or assigned to child pools.

My Solution was

  1. Open Hyper-V manager
  2. Shutdown the default machine or how your docker-machine is called
  3. Then try to open Docker Desktop

I hope this was helpful for someone

Accepted answered 29/7, 2020 at 12:43 Comment(0)
A
0

Everything related to Hyper-V and networking is best resolved by inspecting the problem with the Debug-ContainerHost.ps1 script from microsoft.

To fix corrupted Hyper-V and networking issue use the CleanUpContainerHostNetworking Script from microsoft.

Unfortunately the CleanUp Script only runs on Windows Server but you can just take the ForceCleanUpSystem Method from that script which ran flawelessly on my Windows 11 Pro. After a reboot my docker run and docker networking issues were resolved.

I'll leave it here if somebody needs it:

function ForceCleanupSystem
{
    Param(
        [switch] $ForceDeleteAllSwitches
    )

    $rebootRequired =$false

    RemoveAllContainers
    RemoveAllNetworks

    if ($ForceDeleteAllSwitches.IsPresent)
    {
        if (Test-Path "HKLM:\SYSTEM\CurrentControlSet\Services\vmsmp\parameters\SwitchList")
        {
            $switchList = Get-ChildItem HKLM:\SYSTEM\CurrentControlSet\Services\vmsmp\parameters\SwitchList\ | %{$_.PSPath }

            if ($switchList.count -ne 0)
            {
                Remove-Item -Path HKLM:\SYSTEM\CurrentControlSet\Services\vmsmp\parameters\SwitchList -Recurse -Force
                $rebootRequired = $true
            }
        }

        if (Test-Path "HKLM:\SYSTEM\CurrentControlSet\Services\vmsmp\parameters\NicList")
        {
            $nicList = Get-ChildItem HKLM:\SYSTEM\CurrentControlSet\Services\vmsmp\parameters\NicList\ | %{$_.PSPath }

            if ($nicList.count -ne 0)
            {
                Remove-Item -Path HKLM:\SYSTEM\CurrentControlSet\Services\vmsmp\parameters\NicList -Recurse -Force
                $rebootRequired = $true
            }
        }

        $adapters = Get-NetAdapter

        foreach ($adapter in $adapters)
        {
            if ($adapter.HardwareInterface -eq $true)
            {
                if ($adapter.Name) {
                    Disable-NetAdapterBinding -Name $adapter.Name -ComponentID vms_pp
                } elseif ($adapter.InterfaceDescription) {
                    Disable-NetAdapterBinding -InterfaceDescription $adapter.InterfaceDescription -ComponentID vms_pp
                }
            }
        }

        Get-NetNatStaticMapping | Remove-NetNatStaticMapping -Confirm:$false
        Get-NetNat | Remove-NetNat -Confirm:$false

        if ($rebootRequired)
        {
            Stop-Service hns -Force

            if (Test-Path "C:\ProgramData\Microsoft\Windows\HNS\HNS.data")
            {
                del C:\ProgramData\Microsoft\Windows\HNS\HNS.data
            }
        }

    }

    if(!$rebootRequired)
    {
        Restart-Service hns -ErrorAction SilentlyContinue
        $hns = Get-Service hns

        if ($hns.Status -ne "Running")
        {
            $rebootRequired = $true
        }
    }

    return $rebootRequired
}

Just call it with: ForceCleanupSystem -ForceDeleteAllSwitches

!!!Caution!!! This deletes any virtual networks and resets your host networking service. Read their docs for more information!

Antipathetic answered 13/9, 2023 at 18:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.