Asp.net容器化
注意:本文只用于探讨asp.net容器化,不建议生产环境下使用(docker 镜像太大!!!!)
安装docker
准备一个台windwos server 2016 ,在PowerShell 里执行以下命令
Install-Module DockerProvider -Force
Install-Package Docker -ProviderName DockerProvider -Force
构建简单的网站
FROM microsoft/aspnet:4.7.1 COPY ./www/ /inetpub/wwwroot RUN Add-WindowsFeature Web-IP-Security; ` powershell -NoProfile -Command Install-PackageProvider -Name NuGet -MinimumVersio 2.8.5.201 -Force; \ Install-Module -Name IISAdministration -Force; \ net user web 123456 /add ;\ net localgroup administrators web /add RUN powershell -NoProfile -Command \ Import-module IISAdministration ; \ Remove-IISSite -name 'Default Web Site' -Confirm:$false ; \ New-IISSite -Name "www.example.com" -PhysicalPath "C:\inetpub\wwwroot"
1.通过NuGet安装 IISAdministration,这是一个IIS管理模块,可以通过本地的IIS管理容器中的IIS
2.net user web __Fm9UrD_h /add 设置用户
3.net localgroup administrators web /add 设置用户组
构建HTTPS网站
FROM microsoft/aspnet:4.7.1 RUN mkdir /inetpub/tool COPY ./tool/ /inetpub/tool COPY ./www/ /inetpub/wwwroot RUN Add-WindowsFeature Web-IP-Security; ` certutil -importpfx -p "111111" "C:/inetpub/tool/cert.pfx";\ powershell -NoProfile -Command Install-PackageProvider -Name NuGet -MinimumVersio 2.8.5.201 -Force; \ Install-Module -Name IISAdministration -Force; \ net user web 123456 /add ;\ net localgroup administrators web /add RUN powershell -NoProfile -Command \ Import-module IISAdministration ; \ Remove-IISSite -name 'Default Web Site' -Confirm:$false ; \ New-IISSite -Name "www.example.com" -PhysicalPath "C:\inetpub\wwwroot" -BindingInformation "*:443:www.example.com" -CertificateThumbPrint "52C27E02D8EFB1BB488AEC13DB06E94EED18E539" -CertStoreLocation "Cert:\LocalMachine\My" -Protocol https
1.certutil -importpfx -p "密码" "C:/inetpub/tool/cert.pfx"; 添加证书
2.-CertificateThumbPrint "证书指纹" ,可以通过IIS管理器->服务器证书->查看证书->详细信息->指纹
构建带IIS插件网站
FROM microsoft/aspnet:4.7.1 RUN mkdir /inetpub/tool COPY ./tool/ /inetpub/tool COPY ./www/ /inetpub/wwwroot RUN Add-WindowsFeature Web-IP-Security; ` Start-Process ' C:\inetpub\tool\rewrite_amd64.msi' '/qn' -PassThru | Wait-Process;\ powershell -NoProfile -Command Install-PackageProvider -Name NuGet -MinimumVersio 2.8.5.201 -Force; \ Install-Module -Name IISAdministration -Force; \ net user web 123456 /add ;\ net localgroup administrators web /add RUN powershell -NoProfile -Command \ Import-module IISAdministration ; \ Remove-IISSite -name 'Default Web Site' -Confirm:$false ; \ New-IISSite -Name "www.example.com" -PhysicalPath "C:\inetpub\wwwroot"