I need hyper-v inside a docker container using the image mcr.microsoft.com/windows/servercore:ltsc2019-amd64. When I to enable it by using Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
it fails with:
Install-WindowsFeature : The request to add or remove features on the specified server failed.
Installation of one or more roles, role services, or features failed.
The source files could not be found.
Use the "Source" option to specify the location of the files that are required to restore the feature. For more information on specifying a source location, see
http://go.microsoft.com/fwlink/?LinkId=243077. Error: 0x800f081f
At line:1 char:1
+ Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (@{Vhd=; Credent...Name=localhost}:PSObject) [Install-WindowsFeature], Exception
+ FullyQualifiedErrorId : DISMAPI_Error__Failed_To_Enable_Updates,Microsoft.Windows.ServerManager.Commands.AddWindowsFeatureCommand
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
False No Failed {}
But if I install this role Install-WindowsFeature -Name Hyper-V-PowerShell -IncludeManagementTools
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No NoChangeNeeded {}
it works perfectly. Is there a hardware / nested virtualization requirement that I'm not aware of?
Hyper-V is not supported inside of Windows containers and for that reason the bits for its installation were removed. That's why the first command gives you an error. The second feature you are installing is the PowerShell module for Hyper-V. That module allows you to manage a Hyper-V node from PowerShell - which you can do from a Windows container, hence the success output.
PS C:\Users\Microsoft> Get-WindowsFeature -Name *hyper*
Display Name Name Install State
------------ ---- -------------
[ ] Hyper-V Hyper-V Available
[ ] Hyper-V Management Tools RSAT-Hyper-V-Tools Available
[ ] Hyper-V GUI Management Tools Hyper-V-Tools Available
[ ] Hyper-V Module for Windows PowerShell Hyper-V-PowerShell Available
If you don't mind me asking: what is the scenario that requires you to have Hyper-V installed in a Windows container?