How to make traditional ASP. NET sites run in Docker

Source: Internet
Author: User
Tags creative commons attribution mssqlserver docker run sql server express

This article mainly describes how to get traditional ASP. NET sites to run in Docker, focusing on Docker image setup.
Conditions of Use:

    1. Docker for Windows user switches to Windows container mode
    2. Windows Server 2016 user opens Windows Container

Some conceptual distinctions about Docker for Windows,nanoserver,windows container

    1. Docker for Windows can be installed on both WIN10 and Windows Server 2016, but using Docker for Windows to turn on Windows container is essentially running on Hyper-V. So efficiency is certainly not native high, at the same time Win10 Home Edition user also can not run Windows Container.
    2. Windows Container is "native" on Windows Server 2016, and Windows Container shares the kernel with the host (not verified by bloggers) for enterprise production environments
    3. Nanoserver is a super-lite version of Windows Server 2016, currently Microsoft only allows it to run as a container, because it is a super-simple version, no IIS, but can be deployed manually, as if there is no framework, nature will not run the ASP, but it is due to its streamlining , ideal for Windows production environments as ASP. Details docs.microsoft.com
MSSQL Docker1.1 Dockerfile Way

Refer to GitHub Microsoft/mssql-docker the following microsoft/windowsservercore is slightly different from GitHub, for reference only

From Microsoft/windowsservercore:ltsc2016label 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 accessiblecopy 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, Setuprun 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
Start.ps1
# The script sets the sa password and start the SQL Service # Also It attaches additional database from the disk# the form At for Attach_dbsparam ([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 servicewrite-verbose "starting SQL Server" Start-service MSSQL ' $SQLEXPRESSif ($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 _pas Sword-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-jsonif ($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 .
1.2 Docker Pull Mode
docker pull microsoft/mssql-server-windows-express:2017-CU1
2 Generating container

For SQL Server password rules, click Password Policy
For more information about SQL Server Express Edition in Windows Containers, click SQL Server Express Edition in Windows Containers
NOTE: Although SQL Server is an express version, there is no "\sqlexpress" in the connection instance name

# 非必需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
MySQL Docker (MySQL Container on Windows)

Not yet practiced, for reference only

docker pull dnikolayev/sonarqube-mysql-windows
ASP. Docker1.1 Dockerfile Mode

Refer to Github Microsoft/aspnet-docker

# escape= ' from Microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-ltsc2016shell ["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 Binariesrun 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\\toolsEXPOSE 80ENTRYPOINT ["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 .
1.2 Docker Pull Mode
docker pull microsoft/aspnet:4.7.2-windowsservercore-ltsc2016
2 changing tag (not required) personal habits
docker tag microsoft/aspnet:4.7.2-windowsservercore-ltsc2016 microsoft/aspnet:latest
There are two ways to run a Web site directly by using the ASPNET image
docker run `-d `--link mssql01 `--name siteserver01 `-v C:/Users/Administrator/Desktop/Web/SiteServer01:C:/inetpub/wwwroot `-p 80:80 `--restart=always `microsoft/aspnet
Encapsulating a Web site into a container

Dockerfile
where "." Represents the Web site root directory

FROM microsoft/aspnetCOPY . /inetpub/wwwrootEXPOSE 80
docker build -t yourname/website:version .
docker run --link mssql01 -d -p 80:80 --name website01 --restart=always yourname/website:version
Container Interconnect (another way to choose link)
docker network create website01_networkdocker network connect website01_network website01docker network connect website01_network mssql01
To clean up orphaned data volumes
docker volume ls -qf dangling=true
Reference

Migrating legacy monolithic. NET Framework applications to Windows containers

Migrating an ASP. NET MVC application to the Windows container

This article uses the Creative Commons Attribution-Non-commercial use-the same way to share 2.5 Chinese mainland License Agreement license, welcome reprint, but without the consent of the author must retain this paragraph statement, and in the article page obvious location to give the original text connection.

How to make traditional ASP. NET sites run in Docker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.