Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

WS2016: Start with Windows Containers

  • September 16, 2016
  • 7 min read
Cloud and Virtualization Architect. Florent is specializing in public, hybrid, and private cloud technologies. He is a Microsoft MVP in Cloud and Datacenter Management and an MCSE in Private Cloud.
Cloud and Virtualization Architect. Florent is specializing in public, hybrid, and private cloud technologies. He is a Microsoft MVP in Cloud and Datacenter Management and an MCSE in Private Cloud.

Windows Server
In this article, I’ll explain to you how to start with this new role, on Windows Server 2016 TP5.

To start, you need to install the ContainerImage module on the server that will store containers:

Install-Module –Name ContainerImage

ContainerImage module

Verify that your module is installed correctly:

Get-Module –ListAvailable

ContainerImage module

Now, we will install the role Containers:

Add-WindowsFeature Containers –Restart

the role Containers

With the command Find-ContainerImage, you will have the list of all available images for container base:

command Find-ContainerImage

To install an image, use the following command:

Find-ContainerImage –Name NanoServer | Install-ContainerImage

 install image commandAdministrator Windows PowerShell

Find-ContainerImage –Name WindowsServerCore | Install-ContainerImage

Administrator Windows PowerShellAdministrator Windows PowerShell

Verify that images are correctly installed:

Get-ContainerImage

Container Image

We will now create the network interface, in NAT mode, to give an internet access to containers:

New-ContainerNetwork –Name ‘ContainerNetwork’ –SubnetPrefix 192.168.0.0/24 –Mode NAT

Administrator Windows PowerShell

A NAT rule will be created automatically:

Get-NetNat

NetNat

We will now create our first container, that will store an IIS website. Use the following commands:

$containerNameIIS = "IISCore"
New-Container -Name $containerNameIIS -ContainerImageName WindowsServerCore -NetworkName "ContainerNetwork"
Set-ContainerNetworkAdapter -ContainerName $containerNameIIS -NewName "$containerNameIIS-NetAdapter"
$iisCore = Get-Container -Name $containerNameIIS
$iisCore
Add-ContainerNetworkAdapterStaticMapping -Container $iisCore -AdapterName "$containerNameIIS-NetAdapter" -ExternalPort 82 -InternalPort 80 -Protocol TCP
Start-Container -Name $containerNameIIS

Administrator: Windows PowerShell

Here, we will create a new container, add a port mapping to access to our future IIS website and, finally, we start this container. We’ll now install the IIS role. Connect to your container and launch the installation of the IIS role:

Enter-PSSession -ContainerName $containerNameIIS -RunAsAdministrator
Install-WindowsFeature Web-Server
Get-WindowsFeature Web-Server

Administrator Windows PowerShell

You can now navigate to your new web server, on a container:

web server

I will do an image of this container, to have an IIS base. To start, stop the container, with the command Stop-Container -Name $containerNameIIS. We will now convert this container to do an image. Use the following command:

$iisCore | New-ContainerImage -Publisher FlorentAppointaire -Name $containerNameIIS -Version 1.0
Get-ContainerImage

Container Image

We will create a new container, based on this new image. Use the following command :

$newIISContainer = "IIS01"
New-Container –Name $newIISContainer –ContainerImageName $containerNameIIS -NetworkName “ContainerNetwork”
Set-ContainerNetworkAdapter -ContainerName $newIISContainer -NewName "$newIISContainer-NetAda"
$iisCore = Get-Container $newIISContainer
Add-ContainerNetworkAdapterStaticMapping -Container $iisCore -AdapterName "$newIISContainer-NetAda" -ExternalPort 83 -InternalPort 80 -Protocol TCP
Start-Container $newIISContainer

IIS Windows Server

I’ll now deploy a custom ASP.NET MVC website. I created my site from visual studio 2015:

custom ASP.NET MVC website

ASP.NET project

I customized it:

ASP.NET customization

On the server who are stored containers, I created a shared folder, that I named Share and, where I copied resources of my custom website that I just created. I created a local user, that I added in the local administrator of the server. I shared this folder with this user:

Computer managment

Container Properties

File Sharing

Network folder

I’ll create a new container for this MVC website, because you need some specific features. Use the following commands to install all dependencies and to convert the container to an image:

$containerNameIISMVC = "IISForMvc"
New-Container –Name $containerNameIISMVC –ContainerImageName $containerNameIIS –NetworkName "ContainerNetwork"
Start-Container –Name $containerNameIISMVC
Enter-PSSession -ContainerName $containerNameIISMVC -RunAsAdministrator
Install-WindowsFeature Web-Default-Doc
Install-WindowsFeature Web-Dir-Browsing
Install-WindowsFeature Web-Http-Errors
Install-WindowsFeature Web-Static-Content
Install-WindowsFeature Web-Http-Logging
Install-WindowsFeature Web-Request-Monitor
Install-WindowsFeature Web-Stat-Compression
Install-WindowsFeature Web-Filtering
Install-WindowsFeature Web-Windows-Auth
Install-WindowsFeature Web-Net-Ext45
Install-WindowsFeature Web-Asp-Net45
Install-WindowsFeature Web-ISAPI-Ext
Install-WindowsFeature Web-ISAPI-Filter
Install-WindowsFeature Web-Metabase
Exit
Stop-Container –Name $containerNameIISMVC
Get-Container –Name $containerNameIISMVC | New-ContainerImage –Publisher FlorentAppointaire –Name $containerNameIISMVC –Version 1.0
Get-ContainterImage

Administrator: Windows PowerShell

The last step is to create a new container, based on the last image that we created, and to copy sources of our custom website in this container:

$containerName = "FlorentAppointaireMVC"
New-Container –Name $containerName –ContainerImageName $containerNameIISMVC -NetworkName “ContainerNetwork”
Set-ContainerNetworkAdapter -ContainerName $containerName -NewName "$containerName-NetAda"
$iisCore = Get-Container $containerName
Add-ContainerNetworkAdapterStaticMapping -Container $iisCore -AdapterName "$containerName-NetAda" -ExternalPort 8080 -InternalPort 80 -Protocol TCP
Start-Container $containerName
Enter-PSSession -ContainerName $containerName -RunAsAdministrator
net use z: \\FLOAPP-CONT01\Share /user:FLOAPP-CONT01\Container Password!
Remove-Item C:\inetpub\wwwroot\iisstart.htm 
Remove-Item C:\inetpub\wwwroot\iisstart.png 
Remove-Item C:\inetpub\wwwroot\aspnet_client
Get-ChildItem -Path Z: | % { Copy-Item $_.fullname C:\inetpub\wwwroot -Recurse -Force}
Exit

Administrator: Windows PowerShell

And, if I browse my website on port 8080, I have this result :

ASP.NET window

The movie version (in French) is available here: https://channel9.msdn.com/Blogs/MVP-Cloud-DataCenter/Windows-Container-avec-Windows-Server-2016-TP5

Hey! Found Florent’s article helpful? Looking to deploy a new, easy-to-manage, and cost-effective hyperconverged infrastructure?
Alex Bykovskyi
Alex Bykovskyi StarWind Virtual HCI Appliance Product Manager
Well, we can help you with this one! Building a new hyperconverged environment is a breeze with StarWind Virtual HCI Appliance (VHCA). It’s a complete hyperconverged infrastructure solution that combines hypervisor (vSphere, Hyper-V, Proxmox, or our custom version of KVM), software-defined storage (StarWind VSAN), and streamlined management tools. Interested in diving deeper into VHCA’s capabilities and features? Book your StarWind Virtual HCI Appliance demo today!