Pre-create check: "Hyper-V PowerShell Module is not available"
Please note: this is NOT a duplicate of #4342.
Running docker-for-windows 18.03.0.16511-edge.
Command:
PS C:\Users\pdadmin> docker-machine --debug create -d hyperv --hyperv-virtual-switch "ToInternal" DockerHostA
Docker Machine Version: 0.14.0, build 89b8332
Found binary path at C:\Program Files\Docker\Docker\Resources\bin\docker-machine.exe
Launching plugin server for driver hyperv
Plugin server listening at address 127.0.0.1:49951
() Calling .GetVersion
Using API Version 1
() Calling .SetConfigRaw
() Calling .GetMachineName
(flag-lookup) Calling .GetMachineName
(flag-lookup) Calling .DriverName
(flag-lookup) Calling .GetCreateFlags
Found binary path at C:\Program Files\Docker\Docker\Resources\bin\docker-machine.exe
Launching plugin server for driver hyperv
Plugin server listening at address 127.0.0.1:49955
() Calling .GetVersion
Using API Version 1
() Calling .SetConfigRaw
() Calling .GetMachineName
(DockerHostA) Calling .GetMachineName
(DockerHostA) Calling .DriverName
(DockerHostA) Calling .GetCreateFlags
(DockerHostA) Calling .SetConfigFromFlags
Reading certificate data from C:\Users\pdadmin\.docker\machine\certs\ca.pem
Decoding PEM data...
Parsing certificate...
Reading certificate data from C:\Users\pdadmin\.docker\machine\certs\cert.pem
Decoding PEM data...
Parsing certificate...
Running pre-create checks...
(DockerHostA) Calling .PreCreateCheck
(DockerHostA) DBG | [executing ==>] : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -NonInteractive @(Get-Command hyper-v\Get-VM).ModuleName
(DockerHostA) DBG | [stdout =====>] : hyper-v
(DockerHostA) DBG |
(DockerHostA) DBG | [stderr =====>] :
Error with pre-create check: "Hyper-V PowerShell Module is not available"
notifying bugsnag: [Error with pre-create check: "Hyper-V PowerShell Module is not available"]
The issue is again with https://github.com/docker/machine/blob/master/drivers/hyperv/powershell.go with the hypervAvailable() function.
As you can see by the debug above, trying this in PowerShell...
& "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -NonInteractive "@(Get-Command hyper-v\Get-VM).ModuleName"
...gives you lowercase, i.e. 'hyper-v' and the Go code checks for uppercase 'Hyper-V'.
There are a few solutions.
BEST SOLUTION (in my opinion):
Generally, when determining if a particular PowerShell Module is installed/available, you would use the Get-Module cmdlet. So line 58 in https://github.com/docker/machine/blob/master/drivers/hyperv/powershell.go would go from...
stdout, err := cmdOut("@(Get-Command hyper-v\\Get-VM).ModuleName")
...to...
stdout, err := cmdOut("@(Get-Module -ListAvailable hyper-v).Name | Get-Unique")
SOLUTION 2:
Change line 58 from...
stdout, err := cmdOut("@(Get-Command hyper-v\\Get-VM).ModuleName")
...to...
stdout, err := cmdOut("@(Get-Command Hyper-V\\Get-VM).ModuleName")
SOLUTION 3:
Make line 64...
if resp[0] != "Hyper-V" {
...case insensitive.
I am getting the same issue on Windows Server 2016 VM. Is there a timeline for this fix to be released? Is there a workaround until then?
Any workaround for this on windows 10?
Same Problem. I think the solution should be
stdout, err := cmdOut("@(Get-Module -ListAvailable hyper-v).Name | Get-Unique")
like OP suggested. The same issue exists in Minikube, btw.
@scmikes Workaround is to just install your own base Debian/Ubuntu/CentOS/RedHat VM, create an account called 'docker' with sudo privileges, setup ssh public key auth, and in PowerShell do:
docker-machine create --driver generic --generic-ip-address $VMIPv4Address --generic-ssh-user docker --generic-ssh-key "$("$HOME\.ssh\private_key.pem" -replace "\\","/")" $VMName
I strongly recommend doing this regardless of whether or not this particular bug gets fixed because of this issue that I ran into:
https://github.com/boot2docker/boot2docker/issues/1311
Hi @pldmgg, Where can I find the file that needs to be modified?
Line 58 in https://github.com/docker/machine/blob/master/drivers/hyperv/powershell.go (see above).
I understood that, I can not locate the file on my machine.
@ramit-rulz A workaround is to downgrade docker-machine to v0.13.0
Thanks @samirsyed
Just wanted to verify that I was able to create new docker machine on windows 10 using downgrade to v0.13.0. Thank you very much samirsyed for posting instructions
samirsyed - that worked for me
Same problem here...
docker-machine -version => version 0.14.0, build 89b8332
After the downgrade, it works fine
+1 (@samirsyed's downgrade solution worked for me too. 14 > 13)
Will docker-machine version 13 update in the next update of docker or will be need to do it manually like the downgrade? Thank you all.
Is the status of this bug correct? It looks like a fix was submitted. At least one of the comments has a merge tag
Not sure what's going on here. On my machine when I run from powershell @(Get-Command hyper-v\Get-VM).ModuleName, I'm getting Hyper-V, but when I run from cmd C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -NonInteractive @(Get-Command hyper-v\Get-VM).ModuleName I'm getting hyper-v.
Not sure how ostensibly same command yields two different results. So what's going on here?
SOLUTION 3:
I would suggest to perform a strings.ToLower(). As this guarantees going forward in an 'case insensitive'- way. However, the fix already exists, but is not tagged.
@beppler @shin-
The version tagged as 0.14.0 does works. And the fix is NOT tagged: See, https://github.com/docker/machine/pull/4426 If you pull checksum: e501d1bcb54f09de8ff71aa20010321d18425d19 using Godep it would work. I suggest to create a point release as 0.14.1 containing at least these fixes.
@andrewsav-datacom, most likely your profile configuration is explicit importing the Hyper-V module using the following command.
Import-Module Hyper-V
The case of module name is controlled by the way you explicit import (or not import) the Hyper-V module.
If you don't explicit import it (like when you execute from cmd as you use the -NoProfile switch) it will report hyper-v.
If you explict import the Hyper-V module, powershell will report it with the same case you use on Import-Module.
For example. My profile does not explicit import Hyper-V module so if i run:
Import-Module hyper-V
(Get-Command hyper-v\get-vm).Module.Name
Module name is reported as: hyper-V.
right... but this behaviour also happens when the module is actually loaded. The Import-Module seems to override the value.
Anyways, I believe solution 3 is cleaner for future use... but the current fix (https://github.com/docker/machine/commit/c79bd4ad7404b3c17ff3fd14991dc3f4cddf792e) will do
I also confirmed this earlier today ...

reimporting as Import-Module Hyper-V would override and fix this also