微软一直在投资使用Docker Desktop for Windows在 Windows 上运行 docker 。是否可以通过 Docker 在 IIS 上运行旧版 ASP Classic 应用程序?如何?
3 回答
我终于让这一切正常了。它比运行一个简单的 Dockerfile 复杂得多,因为它是一个最初于 2002 年开发的站点。有必须下载和安装的模块,需要解锁的 web.config 部分,以及需要解锁的 ODBC 数据连接。必须制作。我最终的 docker 文件看起来像这样 - 希望它可以帮助下一个人!
# escape=`
FROM mcr.microsoft.com/windows/servercore/iis
SHELL ["powershell", "-command"]
RUN Install-WindowsFeature Web-ASP; `
Install-WindowsFeature Web-CGI; `
Install-WindowsFeature Web-ISAPI-Ext; `
Install-WindowsFeature Web-ISAPI-Filter; `
Install-WindowsFeature Web-Includes; `
Install-WindowsFeature Web-HTTP-Errors; `
Install-WindowsFeature Web-Common-HTTP; `
Install-WindowsFeature Web-Performance; `
Install-WindowsFeature WAS; `
Import-module IISAdministration;
RUN md c:/msi;
RUN Invoke-WebRequest 'http://download.microsoft.com/download/C/9/E/C9E8180D-4E51-40A6-A9BF-776990D8BCA9/rewrite_amd64.msi' -OutFile c:/msi/urlrewrite2.msi; `
Start-Process 'c:/msi/urlrewrite2.msi' '/qn' -PassThru | Wait-Process;
RUN Invoke-WebRequest 'https://download.microsoft.com/download/1/E/7/1E7B1181-3974-4B29-9A47-CC857B271AA2/English/X64/msodbcsql.msi' -OutFile c:/msi/msodbcsql.msi;
RUN ["cmd", "/S", "/C", "c:\\windows\\syswow64\\msiexec", "/i", "c:\\msi\\msodbcsql.msi", "IACCEPTMSODBCSQLLICENSETERMS=YES", "ADDLOCAL=ALL", "/qn"];
EXPOSE 8000
RUN Remove-Website -Name 'Default Web Site'; `
md c:\mywebsite; `
New-IISSite -Name "mywebsite" `
-PhysicalPath 'c:\mywebsite' `
-BindingInformation "*:8000:";
RUN & c:\windows\system32\inetsrv\appcmd.exe `
unlock config `
/section:system.webServer/asp
RUN & c:\windows\system32\inetsrv\appcmd.exe `
unlock config `
/section:system.webServer/handlers
RUN & c:\windows\system32\inetsrv\appcmd.exe `
unlock config `
/section:system.webServer/modules
RUN Add-OdbcDsn -Name "mywebsite" `
-DriverName "\"ODBC Driver 13 For SQL Server\"" `
-DsnType "System" `
-SetPropertyValue @("\"Server=XXXX.us-east-2.rds.amazonaws.com\"", "\"Trusted_Connection=No\"");
ADD . c:\mywebsite
我没有尝试过,但运行经典 ASP 应该不是问题。该microsoft/iis
映像基于该microsoft/windowsservercore
映像,该映像是完整的 Server Core 安装,还包括 32 位支持。
默认情况下,ASP 功能不存在,因此您的 Dockerfile 必须像这样开始:
# escape=`
FROM microsoft/iis
SHELL ["powershell", "-command"]
RUN Install-WindowsFeature Web-ASP
(escape
和SHELL
行只是让构建 Windows 友好的 Dockerfile 变得更容易,请参阅Windows、Dockerfiles 和 Backtick Backslash Backlash)。
然后您将COPY
在您的 ASP 应用程序文件夹中,并使用 PowerShell 命令运行 IIS 设置的其余部分。这个问题有一些很好的指导,这个 ASP.NET 应用程序的 Dockerfile展示了如何使用 PowerShell 来配置网站。
更新容器运行所在的 Windows Server(使用 Windows 更新)以匹配容器映像版本非常重要。不这样做会引发各种难以追踪的问题。