标签:site += item 分享图片 验证 如何 files log lis
本文主要描述如何让传统ASP.NET网站在Docker中运行,侧重Docker image 搭建。
使用条件:
关于Docker for windows,nanoserver,Windows Container一些概念区分
参考Github Microsoft/mssql-docker 以下内容microsoft/windowsservercore处与Github略有不同,仅供参考
FROM microsoft/windowsservercore:ltsc2016
LABEL maintainer "Perry Skountrianos"
# Download Links:
ENV sql_express_download_url "https://go.microsoft.com/fwlink/?linkid=829176"
ENV sa_password="_" attach_dbs="[]" ACCEPT_EULA="_" sa_password_path="C:\ProgramData\Docker\secrets\sa-password"
SHELL ["powershell", "-Command", "$ErrorActionPreference = ‘Stop‘; $ProgressPreference = ‘SilentlyContinue‘;"]
# make install files accessible
COPY start.ps1 /
WORKDIR /
RUN Invoke-WebRequest -Uri $env:sql_express_download_url -OutFile sqlexpress.exe ; Start-Process -Wait -FilePath .\sqlexpress.exe -ArgumentList /qs, /x:setup ; .\setup\setup.exe /q /ACTION=Install /INSTANCENAME=SQLEXPRESS /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT=‘NT AUTHORITY\System‘ /SQLSYSADMINACCOUNTS=‘BUILTIN\ADMINISTRATORS‘ /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS ; Remove-Item -Recurse -Force sqlexpress.exe, setup
RUN stop-service MSSQL`$SQLEXPRESS ; set-itemproperty -path ‘HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall‘ -name tcpdynamicports -value ‘‘ ; set-itemproperty -path ‘HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall‘ -name tcpport -value 1433 ; set-itemproperty -path ‘HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\‘ -name LoginMode -value 2 ;
CMD .\start -sa_password $env:sa_password -ACCEPT_EULA $env:ACCEPT_EULA -attach_dbs \"$env:attach_dbs\" -Verbose
# The script sets the sa password and start the SQL Service
# Also it attaches additional database from the disk
# The format for attach_dbs
param(
[Parameter(Mandatory=$false)]
[string]$sa_password,
[Parameter(Mandatory=$false)]
[string]$ACCEPT_EULA,
[Parameter(Mandatory=$false)]
[string]$attach_dbs
)
if($ACCEPT_EULA -ne "Y" -And $ACCEPT_EULA -ne "y")
{
Write-Verbose "ERROR: You must accept the End User License Agreement before this container can start."
Write-Verbose "Set the environment variable ACCEPT_EULA to ‘Y‘ if you accept the agreement."
exit 1
}
# start the service
Write-Verbose "Starting SQL Server"
start-service MSSQL`$SQLEXPRESS
if($sa_password -eq "_") {
$secretPath = $env:sa_password_path
if (Test-Path $secretPath) {
$sa_password = Get-Content -Raw $secretPath
}
else {
Write-Verbose "WARN: Using default SA password, secret file not found at: $secretPath"
}
}
if($sa_password -ne "_")
{
Write-Verbose "Changing SA login credentials"
$sqlcmd = "ALTER LOGIN sa with password=" +"‘" + $sa_password + "‘" + ";ALTER LOGIN sa ENABLE;"
& sqlcmd -Q $sqlcmd
}
$attach_dbs_cleaned = $attach_dbs.TrimStart(‘\\‘).TrimEnd(‘\\‘)
$dbs = $attach_dbs_cleaned | ConvertFrom-Json
if ($null -ne $dbs -And $dbs.Length -gt 0)
{
Write-Verbose "Attaching $($dbs.Length) database(s)"
Foreach($db in $dbs)
{
$files = @();
Foreach($file in $db.dbFiles)
{
$files += "(FILENAME = N‘$($file)‘)";
}
$files = $files -join ","
$sqlcmd = "IF EXISTS (SELECT 1 FROM SYS.DATABASES WHERE NAME = ‘" + $($db.dbName) + "‘) BEGIN EXEC sp_detach_db [$($db.dbName)] END;CREATE DATABASE [$($db.dbName)] ON $($files) FOR ATTACH;"
Write-Verbose "Invoke-Sqlcmd -Query $($sqlcmd)"
& sqlcmd -Q $sqlcmd
}
}
Write-Verbose "Started SQL Server."
$lastCheck = (Get-Date).AddSeconds(-2)
while ($true)
{
Get-EventLog -LogName Application -Source "MSSQL*" -After $lastCheck | Select-Object TimeGenerated, EntryType, Message
$lastCheck = Get-Date
Start-Sleep -Seconds 2
}
docker build -t yourname/mssql:2017-CU1 .
docker pull microsoft/mssql-server-windows-express:2017-CU1
SQLServer 密码规则 请点击 Password Policy
有关SQL Server 2016 Express Edition in Windows Containers 请点击 SQL Server 2016 Express Edition in Windows Containers
注意:虽然SQL Server是Express版本的,但连接实例名中没有"\SQLEXPRESS"
# 非必需
docker tag microsoft/mssql-server-windows-express:2017-CU1 microsoft/mssql:latest
# 运行实例
docker run -d -p 1433:1433 --name mssql01 -e sa_password=Qaz123456 -e ACCEPT_EULA=Y --restart=always microsoft/mssql
尚未实践,仅供参考
docker pull dnikolayev/sonarqube-mysql-windows
参考 Github Microsoft/aspnet-docker
# escape=`
FROM microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-ltsc2016
SHELL ["powershell", "-Command", "$ErrorActionPreference = ‘Stop‘; $ProgressPreference = ‘SilentlyContinue‘;"]
RUN Add-WindowsFeature Web-Server; `
Add-WindowsFeature NET-Framework-45-ASPNET; `
Add-WindowsFeature Web-Asp-Net45; `
Remove-Item -Recurse C:\inetpub\wwwroot\*; `
Invoke-WebRequest -Uri https://dotnetbinaries.blob.core.windows.net/servicemonitor/2.0.1.3/ServiceMonitor.exe -OutFile C:\ServiceMonitor.exe
#download Roslyn nupkg and ngen the compiler binaries
RUN Invoke-WebRequest https://api.nuget.org/packages/microsoft.net.compilers.2.8.2.nupkg -OutFile c:\microsoft.net.compilers.2.8.2.zip ; `
Expand-Archive -Path c:\microsoft.net.compilers.2.8.2.zip -DestinationPath c:\RoslynCompilers ; `
Remove-Item c:\microsoft.net.compilers.2.8.2.zip -Force ; `
&C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe update ; `
&C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe update ; `
&C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\csc.exe /ExeConfig:c:\RoslynCompilers\tools\csc.exe | `
&C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\vbc.exe /ExeConfig:c:\RoslynCompilers\tools\vbc.exe | `
&C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\VBCSCompiler.exe /ExeConfig:c:\RoslynCompilers\tools\VBCSCompiler.exe | `
&C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\csc.exe /ExeConfig:c:\RoslynCompilers\tools\csc.exe | `
&C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\vbc.exe /ExeConfig:c:\RoslynCompilers\tools\vbc.exe | `
&C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe install c:\RoslynCompilers\tools\VBCSCompiler.exe /ExeConfig:c:\RoslynCompilers\tools\VBCSCompiler.exe ;
ENV ROSLYN_COMPILER_LOCATION c:\\RoslynCompilers\\tools
EXPOSE 80
ENTRYPOINT ["C:\\ServiceMonitor.exe", "w3svc"]
注意:2018/06/08 访问 https://api.nuget.org/packages/microsoft.net.compilers.2.8.2.nupkg 地址时 CDN 会转换成
https://nuget.cdn.azure.cn/packages/microsoft.net.compilers.2.8.2.nupkg 但这个网址并不存在此文件
docker build -t yourname/websitename:version .
docker pull microsoft/aspnet:4.7.2-windowsservercore-ltsc2016
docker tag microsoft/aspnet:4.7.2-windowsservercore-ltsc2016 microsoft/aspnet:latest
docker run `
-d `
--link mssql01 `
--name siteserver01 `
-v C:/Users/Administrator/Desktop/Web/SiteServer01:C:/inetpub/wwwroot `
-p 80:80 `
--restart=always `
microsoft/aspnet
Dockerfile
其中"."代表网站根目录
FROM microsoft/aspnet
COPY . /inetpub/wwwroot
EXPOSE 80
docker build -t yourname/website:version .
docker run --link mssql01 -d -p 80:80 --name website01 --restart=always yourname/website:version
docker network create website01_network
docker network connect website01_network website01
docker network connect website01_network mssql01
docker volume ls -qf dangling=true
将旧版整体式 .NET Framework 应用程序迁移到 Windows 容器
将 ASP.NET MVC 应用程序迁移到 Windows 容器
标签:site += item 分享图片 验证 如何 files log lis
原文地址:https://www.cnblogs.com/chasingdreams2017/p/9157846.html