Machine: Hyper-v failed to find the first (and only) vswitch

Created on 9 Feb 2015  ·  34Comments  ·  Source: docker/machine

I made a simple internal network, and then shared my internet to it, hoping it would be all dandy.

if I specify it by name, it gets further, but then dies for no documented reason.

svend_000@BIG ~/Downloads
$ docker-machine_windows_amd64-nightly.exe create --driver hyper-v msystest
←[34mINFO←[0m[0001] Creating SSH key...
←[34mINFO←[0m[0002] Creating VM...
←[31mERRO←[0m[0002] Error creating machine: no vswitch found
←[33mWARN←[0m[0002] You will want to check the provider to make sure the machine
 and associated resources were properly removed.
←[31mFATA←[0m[0002] Error creating machine

svend_000@BIG ~/Downloads


svend_000@BIG ~/Downloads
$ docker-machine_windows_amd64-nightly.exe create --driver hyper-v --hyper-v-vi
rtual-switch shared explicit
←[34mINFO←[0m[0001] Creating SSH key...
←[34mINFO←[0m[0002] Creating VM...
←[34mINFO←[0m[0002] Creating VHD
←[31mERRO←[0m[0008] Error creating machine: exit status 1
←[33mWARN←[0m[0008] You will want to check the provider to make sure the machine
 and associated resources were properly removed.
←[31mFATA←[0m[0008] Error creating machine

drivehyperv kinbug

Most helpful comment

Docker Machine works on Hyper-V on Windows 10, tested full end to end. I did have to run docker-machine as Administrator in order for the process to have access to Virtual Machine information.

@StefanScherer I would also recommend using a virtual switch that is external facing. In order to do this through PowerShell you will also need to specify the NetAdapaterInterfaceDescription or the NetAdapterName parameter. https://technet.microsoft.com/en-us/library/hh848455(v=wps.630).aspx

Alternatively you can also do this through Hyper-V Manager under the Actions Pane on the right click Virtual Switch Manager
actionsforswitch

Click New virtual network switch, choose External and hit the Create Virtual Switch button. Once done you can specify the External Network adapter to use in the Virtual Switch Properties.

networkadapter

As per the docs the default behavior is for docker-machine to pick up the first Network Adapter, which can be found by running PS C:\> $Get-VMSwitch

All 34 comments

@jeffmendoza

mm, I'll make a different issue for the failure - this we can document for now, but machine should also tell the user if they don't have permission to make the vm (assuming thats what the problem is)

$ docker-machine_windows_amd64-nightly.exe --debug create --driver hyper-v --hy
per-v-virtual-switch shared explicit2
←[34mDEBU←[0m[0000] [executing ==>] : c:\Windows\System32\WindowsPowerShell\v1.0
\powershell.exe @(Get-Command Get-VM).ModuleName
←[34mDEBU←[0m[0000] [stdout =====>] : Hyper-V

←[34mDEBU←[0m[0000] [stderr =====>] :
←[34mINFO←[0m[0001] Creating SSH key...
←[34mDEBU←[0m[0001] executing: C:\Program Files (x86)\Git\bin\ssh-keygen.exe ssh
-keygen -t rsa -N  -f C:\Users\svend_000\.docker\machines\explicit2\id_rsa

Generating public/private rsa key pair.
Your identification has been saved in C:\Users\svend_000\.docker\machines\explic
it2\id_rsa.
Your public key has been saved in C:\Users\svend_000\.docker\machines\explicit2\
id_rsa.pub.
The key fingerprint is:
6a:e2:c0:ff:1f:7f:38:6b:5a:ab:70:d6:b6:38:8d:8a svend_000@BIG
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|                 |
|        S        |
| .     . .       |
|  o . + +o+.     |
|   + + +o*=o.    |
|    E.oo===+     |
+-----------------+
←[34mINFO←[0m[0003] Creating VM...
←[34mINFO←[0m[0003] Creating VHD
←[34mDEBU←[0m[0003] [executing ==>] : c:\Windows\System32\WindowsPowerShell\v1.0
\powershell.exe New-VHD -Path 'C:\Users\svend_000\.docker\machines\explicit2\fix
ed.vhd' -SizeBytes 10MB -Fixed
←[34mDEBU←[0m[0004] [stdout =====>] :

ComputerName            : BIG
Path                    : C:\Users\svend_000\.docker\machines\explicit2\fixed.v
                          hd
VhdFormat               : VHD
VhdType                 : Fixed
FileSize                : 10486272
Size                    : 10485760
MinimumSize             :
LogicalSectorSize       : 512
PhysicalSectorSize      : 512
BlockSize               : 0
ParentPath              :
DiskIdentifier          : 736c41be-e1d6-4fd0-bac8-4a9a55cd7982
FragmentationPercentage : 0
Alignment               : 1
Attached                : False
DiskNumber              :
Key                     :
IsDeleted               : False
Number                  :




←[34mDEBU←[0m[0004] [stderr =====>] :
←[34mDEBU←[0m[0004] [executing ==>] : c:\Windows\System32\WindowsPowerShell\v1.0
\powershell.exe Convert-VHD -Path 'C:\Users\svend_000\.docker\machines\explicit2
\fixed.vhd' -DestinationPath 'C:\Users\svend_000\.docker\machines\explicit2\disk
.vhd' -VHDType Dynamic
←[34mDEBU←[0m[0006] [stdout =====>] :
←[34mDEBU←[0m[0006] [stderr =====>] :
←[34mDEBU←[0m[0006] [executing ==>] : c:\Windows\System32\WindowsPowerShell\v1.0
\powershell.exe Resize-VHD -Path 'C:\Users\svend_000\.docker\machines\explicit2\
disk.vhd' -SizeBytes 20000MB
←[34mDEBU←[0m[0008] [stdout =====>] :
←[34mDEBU←[0m[0008] [stderr =====>] :
←[34mDEBU←[0m[0008] [executing ==>] : c:\Windows\System32\WindowsPowerShell\v1.0
\powershell.exe New-VM -Name explicit2 -Path 'C:\Users\svend_000\.docker\machine
s\explicit2' -MemoryStartupBytes 1024MB
←[34mDEBU←[0m[0009] [stdout =====>] :
←[34mDEBU←[0m[0009] [stderr =====>] : New-VM : You do not have permission to per
form the operation or the Virtual
Machine Management Service is not running on the target computer or
installation has been corrupted. Please run the cmdlet with proper privilege.
Contact your administrator if you believe you should have permission to
perform this operation, but don't have it yet.
At line:1 char:1
+ New-VM -Name explicit2 -Path 'C:\Users\svend_000\.docker\machines\explicit2'
-Me ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : PermissionDenied: (:) [New-VM], VirtualizationOp

erationFailedException
+ FullyQualifiedErrorId : AccessDenied,Microsoft.HyperV.PowerShell.Command
s.NewVMCommand

←[31mERRO←[0m[0009] Error creating machine: exit status 1
←[33mWARN←[0m[0009] You will want to check the provider to make sure the machine
and associated resources were properly removed.
←[31mFATA←[0m[0009] Error creating machine

svend_000@BIG ~/Downloads
$


mmm, following http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/01/17/allowing-non-administrators-to-control-hyper-v.aspx does not resolve the permissions issue, I guess I'll punt on this for now.

I think we'll need to be in the Administrator role. The powershell I dug up is this:

( New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator )

Will try in a bit, and include a check.

@jeffmendoza I see you updated the readme to say you need to be admin - my user _is_ an admin user, and I get the failure above.

(and at the same time, the above powershell says false. (and it says false when when i run powershell as admin)

I'm presuming that you're doing something different from what the doc says - ie, open any random cmd.exe and type docker-machine create...

Interesting, I am running in a normal terminal, not "run as administrator"

@ehazlett which did you do in your testing?

I was administrator

On Fri, Feb 13, 2015 at 6:29 PM, Jeff Mendoza [email protected]
wrote:

Interesting, I am running in a normal terminal, not "run as administrator"

@ehazlett https://github.com/ehazlett which did you do in your testing?


Reply to this email directly or view it on GitHub
https://github.com/docker/machine/issues/512#issuecomment-74345639.

@jeffmendoza ok, so I'm on Windows 8.1 Enterprise - downloaded from msdn a week or 2 ago - with just my msdn user auto-created - no domain or anything. what are we doing differently?

@ehazlett as in actually logged in as Administrator? or a user that is in the Administrator group, or ?

what does the powershell line above give you?

@SvenDowideit i was running as the Administrator user and that command gives me True

@jeffmendoza any ideas here?

right click the bash and choose "Run as administrator" should work. Windows have more security restriction even you logged in as administrator.

I have exactly the same issue @SvenDowideit Window 8.1 Enterprise downloaded today from MSDN. I have to specify the switch manually with --hyper-v-virtual-switch it is not found automatically. And then I have the permission error you are seeing even though I enabled the exe as "run as administrator".
When I downloaded the exe I think it said the signature was not verifiable.

Ok got that one @SvenDowideit you need to run the command prompt as administrator. In the "Apps" window, right click on the "cmd" and it opens the shell as Administrator

I think there is a problem with ipv6 on windows8. Machine picks up the first IPaddress which is ipv6...seems to be preventing ssh connection to the VM....giving up...back to linux

@runseb ah ok. we could probably adjust the ip command when checking for the IP in virtualbox. sorry for the trouble! thanks for reporting!

I ran into this today - is there a fix / workaround on Windows 8.1?

right click on the "cmd" and it opens the shell as Administrator

Shortcut for all Windows 2000+: Press Window-Key > type cmd > Ctrl+Shift+Enter to run as administrator

As a note, Windows 8.1 has a "Hyper-V Administrators" group that makes it very easy to give a regular user the correct permissions.

The hyper-v drive should attempt an operation and, if it fails, examine the returned error.

@jasonwilliams200OK ah thanks! @znmeb @runseb @SvenDowideit could you try adding yourself to the "Hyper-V Administrators" group to see if that resolves?

@ehazlett as far as I know that does not solve all problems. I will try the latest machine but I don't think this driver works on 8.1 desktop.

@runseb yeah could we just check the original issue with finding the vswitch? /cc @SvenDowideit

mmm, my windows box isn't happy anymore, so I can't be sure any tests I do a relevant atm :/

however, I followed http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/01/17/allowing-non-administrators-to-control-hyper-v.aspx to add my user to the "Hyper-V admins" group when I reported this

and that was not enough for my user to be able to create a Hyper-V machine. (yes, i just checked my user's membership)

Running into the same issue in a fresh Windows 10 VM with Hyper-V installed. There is no virtual switch after installation, so docker-machine gives me the error no vswitch found. I have opened a PowerShell as administrator:

PS C:\Windows\system32> docker-machine -D create -d hyper-v dev
[executing ==>] : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe @(Get-Command Get-VM).ModuleName
[stdout =====>] : Hyper-V

[stderr =====>] :
Creating SSH key...
Creating VM...
[executing ==>] : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe @(Get-VMSwitch).Name
[stdout =====>] :
[stderr =====>] :
Error creating machine: no vswitch found
You will want to check the provider to make sure the machine and associated resources were properly removed.

Then I created a private network with the Hyper-V Manager tool and tried docker-machine again. Then it creates the VM and starts it, but the boot2docker VM does not get any IP address.

So if there is no vswitch at all, should docker-machine just create one with something like this?

new-vmswitch -Name boot2docker -SwitchType Internal

Which SwitchType should be used here?

To test this first vswitch problem I just started a Vagrant box on my Mac with VMware Fusion and enabled nested hypervisor and another vmx setting to make Hyper-V happy. If you need such an environment I can improve the provisioning and provide a Vagrantfile for it. After that I suggest a vagrant snap take and vagrant snap rollback to speed up the feedback loop.

@ahmetalpbalkan @johngossman Can you please take a look at this and confirm it as a bug?

I have no idea about Hyper-V, redirecting the question to @jstarks @jhowardmsft

A private network is just that - private. If you are expecting to get a IP address from an off-box DHCP server you would need an external network in Hyper-V terminology

Docker Machine works on Hyper-V on Windows 10, tested full end to end. I did have to run docker-machine as Administrator in order for the process to have access to Virtual Machine information.

@StefanScherer I would also recommend using a virtual switch that is external facing. In order to do this through PowerShell you will also need to specify the NetAdapaterInterfaceDescription or the NetAdapterName parameter. https://technet.microsoft.com/en-us/library/hh848455(v=wps.630).aspx

Alternatively you can also do this through Hyper-V Manager under the Actions Pane on the right click Virtual Switch Manager
actionsforswitch

Click New virtual network switch, choose External and hit the Create Virtual Switch button. Once done you can specify the External Network adapter to use in the Virtual Switch Properties.

networkadapter

As per the docs the default behavior is for docker-machine to pick up the first Network Adapter, which can be found by running PS C:\> $Get-VMSwitch

@agup006 sadly, things seem to stop working when you switch networks - and on server 2016 tp3, I can't add my wifi as an external network. grumble.
server2016-tp3-private-wifi-vswitch

Hi,
I'm on win10 and was confused by this error. It's possible to solve by going into the Hype-V Manager GUI and manually adding a vswitch. But what would be nicer is a more descriptive error msg. And/or a way to create the missing vswitch on the commandline. As scripted / not through GUI.

This worked for me setting up a "docker" virtual switch and then creating the docker machine.

# create a virtual switch
if (((Get-VMSwitch).name | grep docker) -ne "docker") {
  $description=(Get-NetAdapter).InterfaceDescription | grep -v Hyper-V
  New-VMSwitch -NetAdapterInterfaceDescription $description -Name "docker"

  Write-Host "Waiting for internet connectivity"
  Sleep 15
}

# create a Hyper-V Linux docker machine
docker-machine create -d hyperv --hyperv-virtual-switch "docker" dev

Thanks @StefanScherer - that is indeed helpful lines of powershell to get up and running. Very much so.

BTW:
May I ask about some related choco pkgs? Specifically the 1 for docker-machine itself. It's appreciated too that you contribute those. Just the reason I bring it up is because when try to create new machine with VirtualBox driver, it threw up several other parsing-type error, depending on some other cygwin or unix cmdline tools which perhaps were either missing or broken in my environment...

What I am missing is actually 'docker toolbox' to avoid such issues? As that one seems to say it is also providing with it some kind of 'sanitized' commandline shell that is safe / predictable for docker machine to properly run in. That is correct, yes?

@dreamcat4 In my Vagrant environment I only install Git for Windows with the Unix tools as well which includes ssh.exe.

# install git + ssh
choco install -y git -params "/GitAndUnixToolsOnPath"
# install docker tools
choco install -y docker-machine -version 0.5.1
choco install -y docker-compose -version 1.5.1

Have a look at the repo for more details.

Thanks @dgageot for the fix.

Running (Get-VMSwitch).Name in PowerShell or powershell (Get-VMSwitch).Name in cmd on Windows 10 reports the Virtual switch without requiring run as admin.

C:\>powershell $host.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
5      0      10586  0

C:\>powershell Get-VMSwitch

Name                SwitchType NetAdapterInterfaceDescription
----                ---------- ------------------------------
My External Generic External   This Qualcomm Atheros network Controller connects you to the network.

C:\>powershell (Get-VMSwitch).Name
My External Generic

Instead of throwing ErrNotAdministrator, IMO we should test the exact command which is mandating the administrative privileges for docker and test the return code to figure out the current shell's capability.

Than you @jasonwilliams200OK. It's the creation of an hyper-v vm that need administrative privileges. Doing the check in PreCreateCheck is mandatory otherwise we end up with a half baked machine.

Was this page helpful?
0 / 5 - 0 ratings