【问题标题】:Docker .net framework applicationDocker .net 框架应用程序
【发布时间】:2021-05-04 09:54:42
【问题描述】:

我正在尝试为旧的 .net 框架应用程序(.net 框架 4.6)创建一个工作 docker 映像 到目前为止我做了什么:

  • 我将 Windows 10 上的 Docker 桌面从 Linux 容器切换到 Windows
  • 我通过右键单击“发布”将应用程序部署到目录中
  • 创建构建并运行的 docker 文件

我苦苦挣扎的地方是执行应用程序。 IIS 无法识别应用程序并引发 500 内部服务器错误。

这是我的 docker 文件。

FROM mcr.microsoft.com/windows/servercore/iis

RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*

WORKDIR /inetpub/wwwroot

COPY . .

我接受了https://hub.docker.com/_/microsoft-windows-servercore-iis的指示。

在我的浏览器中导航到页面时,我在运行容器时遇到以下错误。 localhost:8000/application/admin

为了修复错误,我尝试了以下方法:

  • 尝试使用 .net 框架 4.8 和 4.6.2 的图像
  • 更改了connectionstrings
  • CustomErrors 设置为Off
  • wwwroot/inetpub文件夹中文件的权限设置为所有人和完全

不幸的是,我得到了相同的结果。它似乎无法识别该应用程序。我什至很难获得第一个登录页面,因为我在偶数日志中看不到任何内容。

非常感谢任何帮助。提前致谢!

编辑 1:

  • 直接从容器调用Invoke-WebRequest时出现Http错误信息。

  • 修复了 .net 框架版本

【问题讨论】:

  • 您需要获取容器内部的错误页面,以便了解详细的错误信息(或使用appcmd/PowerShell修改IIS设置远程显示详细错误页面),docs.microsoft.com/en-us/iis/configuration/system.webserver/…
  • .net framework 4.8.2 不存在
  • “这是我的 docker 文件。” 这是你的整个 dockerfile 吗?它缺少运行命令,例如CMD ["dotnet", "yourproject.dll"]
  • 感谢@LexLi 我执行了命令,但仍然从外部得到相同的错误。直接从容器调用它时出现不同的错误。添加了上面的消息。
  • @PavelAnikhouski,已修复

标签: asp.net .net docker iis http-status-code-500


【解决方案1】:

感谢所有帮助。它为我指明了正确的方向。必须安装 url re-write 和一些 IIS 模块才能使应用程序正常工作。此外,我在 Docker 桌面混合模式下遇到了 SQL Server linux 映像的问题。但是有一个旧版本的适用于 Windows 的 SQL Server 可以正常工作。 https://hub.docker.com/r/microsoft/mssql-server-windows-developer

这是我的 docker 文件,我希望它可以帮助其他人

FROM mcr.microsoft.com/windows/servercore/iis

RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*

RUN powershell -Command Invoke-WebRequest http://download.microsoft.com/download/D/D/E/DDE57C26-C62C-4C59-A1BB-31D58B36ADA2/rewrite_amd64_en-US.msi -OutFile c:/inetpub/rewrite_amd64_en-US.msi
RUN powershell -Command Start-Process c:/inetpub/rewrite_amd64_en-US.msi -ArgumentList "/qn" -Wait

RUN cmd /c C:\Windows\system32\inetsrv\appcmd.exe  unlock config -section:system.webServer/handlers
RUN cmd /c C:\Windows\system32\inetsrv\appcmd.exe set apppool /apppool.name:DefaultAppPool /enable32BitAppOnWin64:true

RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServer
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-CommonHttpFeatures
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpErrors
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpRedirect
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationDevelopment
RUN powershell -Command Enable-WindowsOptionalFeature -online -FeatureName NetFx4Extended-ASPNET45
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-NetFxExtensibility45
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-HealthAndDiagnostics
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpLogging
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-LoggingLibraries
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-RequestMonitor
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpTracing
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-Security
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-RequestFiltering
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-Performance
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerManagementTools
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-Metabase
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-StaticContent
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-DefaultDocument
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebSockets
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationInit
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIExtensions
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIFilter
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionStatic
RUN powershell -Command Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45

WORKDIR /inetpub/wwwroot

COPY . .

RUN cmd /c icacls C:/inetpub/wwwroot /grant:r Everyone:F /t

【讨论】:

    猜你喜欢
    • 2011-04-24
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多