自 2024 年 3 月开始(1-2 周前)以来,当我拉取最新的 .NET 4.7.2 映像时,dockerfile 中的以下命令停止工作:
FROM mcr.microsoft.com/dotnet/framework/runtime:4.7.2
# install SQL-Server module
RUN powershell -Command \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Install-PackageProvider -Name NuGet -Force; \
Install-Module -Name SqlServer -Force -AllowClobber;
运行此程序时出现以下异常: Install-PackageProvider:找不到指定搜索条件的匹配项 对于提供商“NuGet”。包提供者需要“PackageManagement” 和“提供商”标签。请检查指定包裹是否有标签。
我尝试了以下解决方案来解决该问题:
不用说这一切都不起作用——上述作用的多种组合也起作用。 为了进行分析,这就是我的 dockerfile 现在的样子:
FROM mcr.microsoft.com/dotnet/framework/runtime:4.7.2-20240213-windowsservercore-ltsc2019
# install SQL-Server module
RUN powershell -Command \
Set-ExecutionPolicy Bypass -Scope Process -Force; \
[System.Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \
[Net.ServicePointManager]::SecurityProtocol; \
# Set strong cryptography on 64 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord; \
# Set strong cryptography on 32 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord;
#[Net.ServicePointManager]::SecurityProtocol;
#Get-Module PowerShellGet, PackageManagement -ListAvailable; \
#$PSVersionTable.PSVersion; \
RUN powershell -Command exit;
RUN powershell -Command \
class TrustAllCertsPolicy : System.Net.ICertificatePolicy { [bool] CheckValidationResult([System.Net.ServicePoint] $a, [System.Security.Cryptography.X509Certificates.X509Certificate] $b, [System.Net.WebRequest] $c, [int] $d) { return $true }}; \
[System.Net.ServicePointManager]::CertificatePolicy = [TrustAllCertsPolicy]::new(); \
Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "C:\nuget.exe"; \
Set-Alias nuget "C:\nuget.exe" -Scope Global -Verbose; \
#Install-Module PowerShellGet -Force -AllowClobber; \
#Install-PackageProvider -Name NuGet -Force; \
#Install-PackageProvider -Name 'NuGet' -Source 'PSGallery' -Scope 'CurrentUser' -Verbose -Force; \
#Register-PackageSource -Name "NuGet" -Location "https://api.nuget.org/v3/index.json" -ProviderName NuGet -Force; \
Install-Module -Name SqlServer -Force -AllowClobber -Verbose;
有谁知道问题是什么,或者我错过了什么,或者我下一步可以尝试什么? 欢迎任何建议。
PS.:图中的powershell版本是5.1
针对可能遇到相同问题的每个人的更新: 我找不到它不起作用的原因,但我发现这是一个操作系统问题。因此,我创建了一个新的 Windows Server 2019 VM,安装了 docker,它可以使用最初使用的代码:
FROM mcr.microsoft.com/dotnet/framework/runtime:4.7.2
# install SQL-Server module
RUN powershell -Command \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Install-PackageProvider -Name NuGet -Force; \
Install-Module -Name SqlServer -Force -AllowClobber;
如果有人找到它可以停止工作或停止工作的原因,请在下面发布答案 - 我有兴趣了解这个问题。