Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

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

Closed
pldmgg opened this issue Mar 16, 2018 · 72 comments
Closed

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

pldmgg opened this issue Mar 16, 2018 · 72 comments

Comments

@pldmgg
Copy link

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
…lable

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

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
Copy link

scmikes commented Mar 22, 2018

Any workaround for this on windows 10?

@ChrislyBear-GH
Copy link

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
Copy link
Author

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
Copy link

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

@ckadluba
Copy link

@ajtortolero
Copy link

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

@samirsyed
Copy link

@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
Copy link

Thanks @samirsyed

@scmikes
Copy link

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
Copy link

n1ge1m commented Apr 5, 2018

samirsyed - that worked for me

@borkke
Copy link

borkke commented Apr 8, 2018

Same problem here...

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

After the downgrade, it works fine

@rikkigouda
Copy link

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

@Ouro17
Copy link

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
Copy link

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-bt
Copy link

andrewsav-bt 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
Copy link
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
Copy link
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
Copy link
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
Copy link
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
Copy link

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

@Jishun
Copy link

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
Copy link

@samirsyed Thanks,That worked for me!

@gbraad
Copy link
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...

@mdschweda
Copy link

+1

3 similar comments
@rand0mize71
Copy link

+1

@gopikishanm
Copy link

+1

@potierv
Copy link

potierv commented May 23, 2018

+1

@kantenkugel
Copy link

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
Copy link

Any word on getting this release out?

@gbraad
Copy link
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.

@quisido
Copy link

quisido 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
Copy link

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.

@saif-ellafi
Copy link

+1

1 similar comment
@zhenik
Copy link

zhenik commented Jun 4, 2018

+1

@abigailarreguin
Copy link

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
Copy link

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
Copy link

Doesnt work. switching back to kubernetes.

@q587p
Copy link

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
Copy link

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

@q587p
Copy link

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

@macyan13
Copy link

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-
Copy link
Contributor

shin- commented Jun 12, 2018

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

Thank you for your patience.

@shin- shin- closed this as completed Jun 12, 2018
@ianisms
Copy link

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
Copy link

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
Copy link

mludi commented Jul 18, 2018

Awesome. Thank you @webstandardcss

@programmingwithalex
Copy link

To get the docker-machine command working on PowerShell I followed a similar approach to @webstandardcss.

  1. Went to the docker-machine release page: https://github.com/docker/machine/releases/tag/v0.16.2
  2. Scroll to the bottom and download the latest executable for Windows (currently named docker-machine-Windows-x86_64.exe)
  3. Rename this file to docker-machine.exe
  4. Move this file to C:\Program Files\Docker\Docker\resources\bin

I was then able to run docker-machine in my PowerShell prompt.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests