machine icon indicating copy to clipboard operation
machine copied to clipboard

Pre-create check: "Hyper-V PowerShell Module is not available"

Open pldmgg opened this issue 8 years ago • 72 comments

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.

pldmgg avatar Mar 16 '18 11:03 pldmgg

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?

ramit-rulz avatar Mar 21 '18 17:03 ramit-rulz

Any workaround for this on windows 10?

scmikes avatar Mar 22 '18 01:03 scmikes

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.

ChrislyBear-GH avatar Mar 22 '18 13:03 ChrislyBear-GH

@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

pldmgg avatar Mar 22 '18 15:03 pldmgg

Hi @pldmgg, Where can I find the file that needs to be modified?

ajtortolero avatar Mar 31 '18 03:03 ajtortolero

Line 58 in https://github.com/docker/machine/blob/master/drivers/hyperv/powershell.go (see above).

ckadluba avatar Mar 31 '18 10:03 ckadluba

I understood that, I can not locate the file on my machine.

ajtortolero avatar Mar 31 '18 20:03 ajtortolero

@ramit-rulz A workaround is to downgrade docker-machine to v0.13.0

  1. Download 32-bit or 64-bit version
  2. Replace C:\Program Files\Docker\Docker\resources\bin\docker-machine.exe with the newly downloaded file.

samirsyed avatar Mar 31 '18 22:03 samirsyed

Thanks @samirsyed

ajtortolero avatar Apr 01 '18 05:04 ajtortolero

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

scmikes avatar Apr 02 '18 14:04 scmikes

samirsyed - that worked for me

n1ge1m avatar Apr 05 '18 19:04 n1ge1m

Same problem here...

docker-machine -version => version 0.14.0, build 89b8332

After the downgrade, it works fine

borkke avatar Apr 08 '18 19:04 borkke

+1 (@samirsyed's downgrade solution worked for me too. 14 > 13)

rikkigouda avatar Apr 09 '18 05:04 rikkigouda

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.

Ouro17 avatar Apr 10 '18 12:04 Ouro17

Is the status of this bug correct? It looks like a fix was submitted. At least one of the comments has a merge tag

scmikes avatar Apr 10 '18 12:04 scmikes

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?

andrewsav-bt avatar Apr 11 '18 02:04 andrewsav-bt

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.

gbraad avatar Apr 12 '18 05:04 gbraad

@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.

beppler avatar Apr 12 '18 11:04 beppler

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

gbraad avatar Apr 12 '18 12:04 gbraad

I also confirmed this earlier today ... image

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

gbraad avatar Apr 12 '18 12:04 gbraad