在IIS上使用Docker化ASP Classic

30

微软一直在投资于在Windows上运行Docker,使用Docker Desktop for Windows。是否可以通过Docker在IIS上运行传统的ASP Classic应用程序?如何操作?

https://hub.docker.com/r/microsoft/iis/

2个回答

58

我终于把这个东西搞定了。它比运行一个简单的 Dockerfile 要复杂得多,因为它是一个最初开发于2002年的网站。必须下载和安装模块,解锁 Web.config 部分,并建立 ODBC 数据连接。我的最终 Dockerfile 如下-希望能对下一个人有所帮助!

# 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

Elton Stoneman 的答案对我开了一个很好的头,因此请确保在下面查看,以获得更好的理解。 - Patrick Lee Scott
这可能是一个愚蠢的问题,但是你如何在 Windows 机器上实际部署它?它是否支持 CI/CD?SQL 数据库是在 Docker 容器内还是外部运行? - Umar.H
2
CI/CD是一个完全独立的过程-您可以在CI/CD过程中使用Dockerfiles。数据库将在此容器之外运行,可能在另一个容器或裸机上运行-这超出了此容器的关注范围。至于如何在Windows上部署-运行像Kubernetes这样的编排工具。查找kube for windows的文档并遵循那些文档。 - Patrick Lee Scott
1
https://kubernetes.io/docs/setup/production-environment/windows/intro-windows-in-kubernetes/ - Patrick Lee Scott
哎呀,容器似乎不再存在了,很遗憾,因为我想为客户的旧网站测试这个。 - Steven Matthews
1
我能够找到这个可用的镜像:mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2022 - Steven Matthews

6

我还没有尝试过,但运行经典ASP应该不是问题。 microsoft/iis 镜像基于 microsoft/windowsservercore 镜像构建而成,后者是完整的Server Core安装版本,同时也包含32位支持。

ASP功能默认不会存在,因此您的Dockerfile应该从以下内容开始:

# escape=`
FROM microsoft/iis
SHELL ["powershell", "-command"]
RUN Install-WindowsFeature Web-ASP

escapeSHELL行只是为了更容易构建友好于Windows的Dockerfile,详情请参见Windows、Dockerfile和反引号反斜杠反斜杠
然后您将会COPY您的ASP应用程序文件夹,并使用PowerShell命令运行其余的IIS设置。 这个问题提供了一些很好的指导,而这个ASP.NET应用程序的Dockerfile则展示了如何使用PowerShell配置网站。

太棒了,我很想尝试,但是遇到了一个新问题 - Docker Hub 上的 windowsservercore 镜像似乎损坏了 - 在两台机器和两个网络上都尝试过,但是无法成功下载 :( - Patrick Lee Scott
➜ docker pull microsoft/windowsservercore 正在使用默认标签: latest 正在从 microsoft/windowsservercore 拉取9c7f9c7d9bc2: 9秒后重试 de5064718b3f: 10秒后重试最终出现"未知的块" - Patrick Lee Scott
1
猜测这是因为你只能在 Windows 上运行 Windows 容器 :( - Patrick Lee Scott
如果您正在使用Windows Server 2016,请确保运行Windows更新 - 在Windows 10上,您需要加入Insider计划。使用最新版本的时候,我在Hub方面没有任何问题。 - Elton Stoneman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接