在Windows Server Core Docker上安装.NET Framework 3.5

Mil*_*vic 11 .net c# docker dockerfile

我正在努力在docker容器上安装.NET Framework 3.5.我已经安装了4.5,但需要3.5才能运行一个服务.这是我的Dockerfile:

FROM microsoft/windowsservercore
SHELL ["powershell"]


RUN Install-WindowsFeature NET-Framework-45-ASPNET ; \  
    Install-WindowsFeature Web-Asp-Net45

RUN dism /online /enable-feature /featurename:NetFX3 /all

COPY Startup Startup
COPY Service Service



RUN "C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe" WCS.WindowsService.exe


RUN mkdir Temp\Logs

ENTRYPOINT C:\Startup\setupBatch.bat

COPY ContainerApi ContainerApi

RUN Remove-WebSite -Name 'Default Web Site'  
RUN New-Website -Name 'ContainerApi' -Port 80 \  
    -PhysicalPath 'C:\ContainerApi' -ApplicationPool '.NET v4.5'

EXPOSE 80

CMD ["ping", "-t", "localhost"]  
Run Code Online (Sandbox Code Playgroud)

当我尝试构建它时,它会让我在线错误 RUN dism

错误:0x800f081f

找不到源文件.
使用"源"选项指定还原功能所需文件的位置.有关指定源位置的详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=243077.

现在,即使我dism /online /enable-feature /featurename:NetFX3 /all在docker(docker exec)内部运行,它仍然会给我同样的错误.

有帮助的人吗?

ans*_*iwn 12

我采取了以下步骤来解决此问题:

  1. 掌握了Windows Server 2016 Core ISO文件.在本地计算机上安装文件.
  2. 将{mount}:/ sources/sxs文件夹解压缩为zip文件(sxs.zip).确保sxs文件夹中存在.NET Framework 3.5 cab文件(microsoft-windows-netfx3-ondemand-package.cab).就我而言,这是sxs文件夹中唯一存在的文件.

sxs文件夹

  1. 将sxs.zip文件复制到我的容器中.我使用图像的dockerfile复制了它.
  2. 将文件解压缩到容器中的C:\ sources\sxs文件夹.
  3. 使用Install-WindowsFeature powershell命令安装该功能.

    Install-WindowsFeature -Name NET-Framework-Features -Source C:\sources\sxs -Verbose
    
    Run Code Online (Sandbox Code Playgroud)

    安装命令

希望这可以帮助.我还发现以下博客有助于理解按需功能. https://blogs.technet.microsoft.com/askcore/2012/05/14/windows-8-and-net-framework-3-5/


csa*_*ong 8

对于那些仍然需要 .Net3.5 和 .Net4.X(我的情况是 4.7.2)版本的人来说。

请注意,MSFT 意识到了这种需求,并为这种情况提供了基础映像。

FROM mcr.microsoft.com/dotnet/framework/sdk:3.5-20191008-windowsservercore-ltsc2019在您的 dockerfile 中使用。

为我省去了所有安装麻烦。