And*_*eas 5 windows .net-3.5 .net-framework docker
我正在尝试从使用 .NET 3.5 的本地构建环境中创建一个 docker 映像。我尝试启用该功能但收到错误。
这是我用于重现问题的最小化 docker 文件:
FROM mcr.microsoft.com/dotnet/framework/sdk
RUN powershell "Install-WindowsFeature -Name NET-Framework-Features -Verbose"
Run Code Online (Sandbox Code Playgroud)
这是输出:
Sending build context to Docker daemon 72.74MB
Step 1/2 : FROM mcr.microsoft.com/dotnet/framework/sdk
---> 88afad8be364
Step 2/2 : RUN powershell "Install-WindowsFeature -Name NET-Framework-Features -Verbose"
---> Running in 0a377584126e
VERBOSE: Installation started...
VERBOSE: Continue with installation?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.
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 service cannot be started, either because it is disabled or because it has
no enabled devices associated with it. Error: 0x80070422
At line:1 char:1
+ Install-WindowsFeature -Name NET-Framework-Features -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (@{Vhd=; Credent...Name=localh
ost}:PSObject) [Install-WindowsFeature], Exception
+ FullyQualifiedErrorId : DISMAPI_Error__Failed_To_Enable_Updates,Microsof
t.Windows.ServerManager.Commands.AddWindowsFeatureCommand
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
False No Failed {}
VERBOSE: Installation succeeded.
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; powershell "Install-WindowsFeature -Name NET-Framework-Features -Verbose"' returned a non-zero code: 1
Run Code Online (Sandbox Code Playgroud)
构建并运行裸映像而不尝试安装(步骤 2/2)并检查功能显示 3.5 是一个选项:
C:\>powershell "Get-WindowsFeature net*"
Display Name Name Install State
------------ ---- -------------
[ ] .NET Framework 3.5 Features NET-Framework-Features Available
[ ] .NET Framework 3.5 (includes .NET 2.0 and 3.0) NET-Framework-Core Removed
[ ] HTTP Activation NET-HTTP-Activation Available
[ ] Non-HTTP Activation NET-Non-HTTP-Activ Available
[X] .NET Framework 4.8 Features NET-Framework-45-Fea... Installed
[X] .NET Framework 4.8 NET-Framework-45-Core Installed
[ ] ASP.NET 4.8 NET-Framework-45-ASPNET Available
[X] WCF Services NET-WCF-Services45 Installed
[ ] HTTP Activation NET-WCF-HTTP-Activat... Available
[ ] Message Queuing (MSMQ) Activation NET-WCF-MSMQ-Activat... Available
[ ] Named Pipe Activation NET-WCF-Pipe-Activat... Available
[ ] TCP Activation NET-WCF-TCP-Activati... Available
[X] TCP Port Sharing NET-WCF-TCP-PortShar... Installed
[ ] Network Virtualization NetworkVirtualization Removed
Run Code Online (Sandbox Code Playgroud)
我尝试启用NET-Framework-45-ASPNET,似乎工作得很好,但它再次被列为,而Available被NET-Framework-Core列为Removed.
进一步研究如何修复该Removed状态,建议将来自操作系统安装 ISO 的包含 -files 的文件夹.cab列为-Source. 但是 cmd 返回的操作系统名称sysinfo是普通的Microsoft,没有相应的 ISO。我尝试下载Windows Server 2019 ISO并使用它的source/sxsas -Source,希望得到最好的结果,但有相同的错误结果和输出(新的 Dockerfile):
FROM mcr.microsoft.com/dotnet/framework/sdk
# Copy sources/sxs from Windows Server 2016 ISO
COPY sources\sxs2016 C:\sources\sxs
RUN powershell "Install-WindowsFeature NET-Framework-Features -Source C:\sources\sxs -Verbose"
Run Code Online (Sandbox Code Playgroud)
有什么想法可以让这项工作发挥作用吗?
发生该错误的原因是它正在尝试使用 Windows Update 服务,而该服务在基本容器中被禁用。即使直接向安装程序提供带有源的本地路径也是如此。
使原始 Dockerfile 工作的最简单的更改是在安装之前启用 Windows Update 服务:
FROM mcr.microsoft.com/dotnet/framework/sdk
RUN powershell "Set-Service -Name wuauserv -StartupType Manual; Install-WindowsFeature -Name NET-Framework-Features -Verbose"
Run Code Online (Sandbox Code Playgroud)
同样的方法适用于 Powershell 脚本,其中 .NET Framework 3.5 源已复制到本地:
Set-Service -Name wuauserv -StartupType "Manual"
write-output "Installing Windows Feature .net framework 35"
Install-WindowsFeature -Name NET-Framework-Features -Source C:\NET-Framework35-Features -Verbose
Run Code Online (Sandbox Code Playgroud)
出于简单性和可维护性的考虑,与 Microsoft 在官方映像中使用的内容相比,这可能仍然更可取。他们直接引用特定版本并根据需要更新这些版本。
| 归档时间: |
|
| 查看次数: |
6889 次 |
| 最近记录: |