Windows Server 2016: Create Container Template with ASP.Net

The new Windows Server 2016 TP4 introduces many improvements into Containers. For more info about it, check my article.


From the Web Server side, now it’s possible deploy .Net applications very faster. So let see how to create a Container template with a web site on ASP.Net 4.6.


First of all, create a new Container with cmdlet:


New-Container -Name Tmp01 -ContainerImageName WindowsServerCore -SwitchName “Virtual Switch”


Start the Container and enter into the session:


Start-Container -Name Tmp01
Enter-PSSession -ContainerName Tmp01 -RunAsAdministrator


When you are into the Container, run these cmdlets to enable IIS and ASP.Net:


Install-WindowsFeature Web-Server
Install-WindowsFeature Web-Asp-Net45


Inject your web site files:


wget -uri ‘http://www.internalportal.lcl/’ -OutFile “c:\”
Expand-Archive -Path C:\ -DestinationPath “C:\inetpub\wwwroot\” -Force
Del “c:\”


The .zip file must contain all the files/folders. Remove the iisstart.htm into C:\inetpub\wwwroot\.


Close the remote session. Before generate the template, is better test the solution. To do this, is necessary configure a NAT/Firewall rule into Container Host:


New-NetFirewallRule -Name “Container Default Web” -DisplayName “Container Default Web” -Protocol TCP -LocalPort 80 -Action Allow
New-NetFirewallRule -Name “Container NAT Tmp01” -DisplayName “Container NAT Tmp01” -Protocol TCP -LocalPort 800 -Action Allow
Add-NetNatStaticMapping -NatName ContainerNAT -Protocol TCP -ExternalPort 800 -ExternalIPAddress -InternalPort 80 -InternalIPAddress


Open a browser windows from your client and test the web site with the IP address of your Container Host plus NAT port (es., as showed in figure 1.


Figure 1 – Container with ASP.Net


If it’s all ok, you can stop the Container and create the template with these cmdlets:


Stop-Container -Name Tmp01
New-ContainerImage -ContainerName Tmp01 -Name MyWebSiteASP -Publisher “My Company” -Version 1.0


Remove the test rules:


Remove-NetFirewallRule -DisplayName “Container NAT Tmp01”
Get-NetNatStaticMapping | Remove-NetNatStaticMapping


Now you are ready to create new Containers with the new template.


Remember to use my PowerShell script to create/manage/remove Containers with NAT, available on TechNet Gallery.