在 docker 容器内启用 Hyper-v

Enable Hyper-v inside docker container

我需要使用图像 mcr.microsoft.com/windows/servercore:ltsc2019-amd64 在 docker 容器中使用 hyper-v。当我使用 Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart 启用它时,它失败了:

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         {}

但是如果我安装这个角色Install-WindowsFeature -Name Hyper-V-PowerShell -IncludeManagementTools

Success Restart Needed Exit Code      Feature Result
------- -------------- ---------      --------------
True    No             NoChangeNeeded {}

它工作得很好。是否存在我不知道的硬件/嵌套虚拟化要求?

Hyper-V 在 Windows 容器内不受支持,因此删除了安装位。这就是第一个命令给您错误的原因。 您要安装的第二个功能是 Hyper-V 的 PowerShell 模块。该模块允许您从 PowerShell 管理 Hyper-V 节点 - 您可以从 Windows 容器执行此操作,因此输出成功。

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

如果您不介意我问:在什么情况下需要您在 Windows 容器中安装 Hyper-V?