New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pldmgg opened this Issue Mar 16, 2018 · 71 comments

Comments

Projects
None yet
@pldmgg

pldmgg commented Mar 16, 2018

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.

dgageot added a commit that referenced this issue Mar 20, 2018

Merge pull request #4426 from beppler/4424-powershell-module-not-avai…
…lable

Fix issue #4424 - Pre-create check: "Hyper-V PowerShell Module is not available"
@ramit-rulz

This comment has been minimized.

ramit-rulz commented Mar 21, 2018

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?

@scmikes

This comment has been minimized.

scmikes commented Mar 22, 2018

Any workaround for this on windows 10?

@Chrisly3ear

This comment has been minimized.

Chrisly3ear commented Mar 22, 2018

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.

@pldmgg

This comment has been minimized.

pldmgg commented Mar 22, 2018

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

boot2docker/boot2docker#1311

@ajtortolero

This comment has been minimized.

ajtortolero commented Mar 31, 2018

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

@ckadluba

This comment has been minimized.

@ajtortolero

This comment has been minimized.

ajtortolero commented Mar 31, 2018

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

@samirsyed

This comment has been minimized.

samirsyed commented Mar 31, 2018

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

This comment has been minimized.

ajtortolero commented Apr 1, 2018

Thanks @samirsyed

@scmikes

This comment has been minimized.

scmikes commented Apr 2, 2018

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

@n1ge1m

This comment has been minimized.

n1ge1m commented Apr 5, 2018

samirsyed - that worked for me

@borkke

This comment has been minimized.

borkke commented Apr 8, 2018

Same problem here...

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

After the downgrade, it works fine

@goudarzi

This comment has been minimized.

goudarzi commented Apr 9, 2018

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

@Ouro17

This comment has been minimized.

Ouro17 commented Apr 10, 2018

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.

@scmikes

This comment has been minimized.

scmikes commented Apr 10, 2018

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

@andrewsav-datacom

This comment has been minimized.

andrewsav-datacom commented Apr 11, 2018

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?

@gbraad

This comment has been minimized.

Contributor

gbraad commented Apr 12, 2018

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, #4426 If you pull checksum: e501d1b using Godep it would work. I suggest to create a point release as 0.14.1 containing at least these fixes.

@beppler

This comment has been minimized.

Contributor

beppler commented Apr 12, 2018

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

@gbraad

This comment has been minimized.

Contributor

gbraad commented Apr 12, 2018

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 (c79bd4a) will do

@gbraad

This comment has been minimized.

Contributor

gbraad commented Apr 12, 2018

I also confirmed this earlier today ...
image

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

@MikyChow

This comment has been minimized.

MikyChow commented Apr 12, 2018

@gbraad try docker --debug create -d hyperv yourmachinename,then get the debug info.

@Jishun

This comment has been minimized.

Jishun commented Apr 13, 2018

I'm able to manipulate the module name shown with get-command hyper-v\get-vm by remove-module then import-module in the case that I want
but whichever case I tried, it docker-machine gives this same error

@MikyChow

This comment has been minimized.

MikyChow commented Apr 13, 2018

@samirsyed Thanks,That worked for me!

@gbraad

This comment has been minimized.

Contributor

gbraad commented Apr 13, 2018

@MikyChow no need to collect this. We already know what the issue is:

func hypervAvailable() error {
stdout, err := cmdOut("@(Get-Module -ListAvailable hyper-v).Name | Get-Unique")
if err != nil {
return err
}
resp := parseLines(stdout)
if resp[0] != "Hyper-V" {
return ErrNotInstalled
}
return nil
}

It's OK for us (minikube, minishift) now. The check works... but the release as 0.14.1 or whatever was never made, so pulling docker/machine as dependency has to be done on a sha hash and this is far from ideal.

Although, it would be better to make the != "Hyper-V" check not case-sensitive...

@jplonghi

This comment has been minimized.

jplonghi commented May 17, 2018

+1

6 similar comments
@anikanovna

This comment has been minimized.

anikanovna commented May 18, 2018

+1

@crowdy

This comment has been minimized.

crowdy commented May 20, 2018

+1

@mdschweda

This comment has been minimized.

mdschweda commented May 22, 2018

+1

@rand0mize71

This comment has been minimized.

rand0mize71 commented May 22, 2018

+1

@gopikishanm

This comment has been minimized.

gopikishanm commented May 23, 2018

+1

@potierv

This comment has been minimized.

potierv commented May 23, 2018

+1

@kantenkugel

This comment has been minimized.

kantenkugel commented May 23, 2018

Guys, can you please stop +1ing? If you want to show your support, just add an reaction or w/e.

This doesn't boost the speed of implementation at all. Just annoys people subscribed to the thread to see when actual updates happen.

@dasmedium

This comment has been minimized.

dasmedium commented May 31, 2018

Any word on getting this release out?

@gbraad

This comment has been minimized.

Contributor

gbraad commented May 31, 2018

The time it takes is telling for the maintenance and support of this library. We have already forked this as part of docker-machines/machine, and are considering to do our own releases instead.

@CharlesStover

This comment has been minimized.

CharlesStover commented Jun 1, 2018

Verifying for anyone also finding this via Google that downgrading from 0.14 to 0.13 resolves this issue. Practically pulled my hair out trying to get the docker machine to start. Thanks @samirsyed.

@gmsantos

This comment has been minimized.

gmsantos commented Jun 2, 2018

Downgrading to 0.13 didn't worked for me, but building from master branch worked well.

See CONTRIBUTING.md for more details on how to build from source.

I hope docker maintainers release a new version soon.

@saifjsl

This comment has been minimized.

saifjsl commented Jun 3, 2018

+1

1 similar comment
@NikitaZhevnitskiy

This comment has been minimized.

NikitaZhevnitskiy commented Jun 4, 2018

+1

@abigailarreguin

This comment has been minimized.

abigailarreguin commented Jun 4, 2018

I had this same issue for awhile. I installed the docker toolbox and that's all it took to work. I already met all the requirements so I am guessing there were specific versions I needed that were within the toolbox. I am all set up and running now. Hope this helps!

@m-suizu

This comment has been minimized.

m-suizu commented Jun 6, 2018

PS C:\> docker-machine --version
docker-machine.exe version 0.14.0, build 89b8332

PS C:\> Import-Module Hyper-v
PS C:\> (Get-Command hyper-v\get-vm).Module.Name
Hyper-v

PS C:\> docker-machine --debug create -d hyperv --hyperv-virtual-switch dockerswitch vm

...

Running pre-create checks...
(local-squid) Calling .PreCreateCheck
(local-squid) DBG | [executing ==>] : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -NonInteractive @(Get-Command hyper-v\Get-VM).ModuleName
(local-squid) DBG | [stdout =====>] : hyper-v
(local-squid) DBG |
(local-squid) DBG | [stderr =====>] :
Error with pre-create check: "Hyper-V PowerShell Module is not available"
@nigel-dewar

This comment has been minimized.

nigel-dewar commented Jun 6, 2018

Doesnt work. switching back to kubernetes.

@q587p

This comment has been minimized.

q587p commented Jun 8, 2018

Microsoft Windows [Version 10.0.17134.48]
Linux q587p-work 4.4.0-17134-Microsoft №48-Microsoft Fri Apr 27 18:06:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
Docker version 18.03.1-ce, build 9ee9f40

Downgrade to 0.13 (thnx @samirsyed) helps with
Error with pre-create check: "Hyper-V PowerShell Module is not available"

But now I have next problem:
Error with pre-create check: "Hyper-v commands have to be run as an Administrator"

If I used .exe then this is simple way to change this (C:\Program Files\Docker\Docker\resources\bin\docker-machine.exe → right click and select Compatibility and check the box "Run this program as an administrator").

But how and where change this permission in WSL?..

P. S. Currently I try to use downgraded windows version of docker-machine and get this error: #2267

@kantenkugel

This comment has been minimized.

kantenkugel commented Jun 8, 2018

@q587p Just run your bash / shell / command line as administrator. That should fix it. WSL might already work with sudo

@q587p

This comment has been minimized.

q587p commented Jun 8, 2018

Thnx @kantenkugel! It wasn't obvious.

Next one appears:

Error creating machine: Error in driver during machine creation: open /root/.docker/machine/machines/myvm1/fixed.vhd: no such file or directory

@Yan-Matskevich

This comment has been minimized.

Yan-Matskevich commented Jun 10, 2018

Have the same issue with "Hyper-V PowerShell Module is not available" error and downgrade to version 0.13 doesn't solve the problem ( with old one a have another problem). As a workaround I use Oracle VM virtualbox now. So is there any news about new docker-machine version with resolved issue :)

@shin-

This comment has been minimized.

Member

shin- commented Jun 12, 2018

https://github.com/docker/machine/releases/tag/v0.15.0

Thank you for your patience.

@shin- shin- closed this Jun 12, 2018

@ianisms

This comment has been minimized.

ianisms commented Jun 27, 2018

I have the same issue with 0.15: Error with pre-create check: "Hyper-V PowerShell Module is not available"
winver: 1803 (OS Build 17692.1000)
docker-machine version 0.15.0, build b48dc28

@webstandardcss

This comment has been minimized.

webstandardcss commented Jul 17, 2018

Here is the solution

https://github.com/docker/machine/releases/download/v0.15.0/docker-machine-Windows-x86_64.exe

Save the downloaded file to your existing directory containing docker-machine.exe.

For my system this is the location for docker-machine.exe
/c/Program Files/Docker/Docker/Resources/bin/docker-machine.exe

Backup the old file and replace it file with the new one.

cp docker-machine.exe docker-machine.014.exe

Rename the downloaded filename to docker-machine.exe

mv docker-machine-Windows-x86_64.exe docker-machine.exe

Build Instructions

  1. Create virtual switch in Hyper-V manager named myswitch
  2. Request Docker to create a VM named myvm1

docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm1

Results

docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm1

Running pre-create checks...
(myvm1) Image cache directory does not exist, creating it at C:\Users\Trey Brister\.docker\machine\cache...
(myvm1) No default Boot2Docker ISO found locally, downloading the latest release...
(myvm1) Latest release for github.com/boot2docker/boot2docker is v18.05.0-ce
(myvm1) Downloading C:\Users\Trey Brister\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.05.0-ce/boot2docker.iso...
(myvm1) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Creating machine...
(myvm1) Copying C:\Users\Trey Brister\.docker\machine\cache\boot2docker.iso to C:\Users\Trey Brister\.docker\machine\machines\myvm1\boot2docker.iso...
(myvm1) Creating SSH key...
(myvm1) Creating VM...
(myvm1) Using switch "myswitch"
(myvm1) Creating VHD
(myvm1) Starting VM...
(myvm1) Waiting for host to start...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:\Program Files\Docker\Docker\Resources\bin\docker-machine.exe env myvm1
@mludi

This comment has been minimized.

mludi commented Jul 18, 2018

Awesome. Thank you @webstandardcss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment