Sergey Nivens - Fotolia

Tip

Deploy Microsoft IIS server, .NET apps in Windows containers

Instead of investing money in migrating your existing .NET applications to .NET Core to modernize them, deploy them in Windows containers with a simple script.

Unfortunately, you can't migrate certain legacy applications to the cloud without modernizing them, which can be both costly and time-consuming. To work around that, you can deploy Microsoft IIS server and .NET applications to Windows containers.

Once you deploy Windows containers in your production environment, you can deploy services to them. For example, you can deploy Microsoft Internet Information Services (IIS) in Windows containers and any applications that Windows containers support. First, you must install a Windows Server Core VM, create a container inside the VM, install Docker engine, pull Docker images and then implement the container with an IIS image.

Benefits of using .NET applications in Windows containers

The benefits of Windows containers include improved agility, portability, isolation and control. The major benefit of running .NET applications in Windows containers is that containers offer a way to modernize existing .NET applications that run on Windows platforms. If you don't want to invest in migrating .NET Framework applications to .NET Core, then you can deploy these applications in Windows containers by pulling a Nano Server image.

The end result is that you're running your existing .NET applications in Windows containers with the full support of the Windows OS and other dependencies, such as Microsoft IIS server and System.Web. It's worth trying to use existing Docker Engine images before investing money on migrating .NET applications to .NET Core.

Requirements and steps for installing Microsoft IIS server in containers

Before you install Microsoft IIS server, you must meet certain requirements. First, you must create a Hyper-V VM that runs Windows Server Core 2016 and connect the VM to a Hyper-V switch. The Hyper-V switch connection is what makes Microsoft IIS server available outside of the host OS.

At a high level, you must install Docker Engine, run Windows updates to ensure Server Core OS is up to date and run a container with Microsoft IIS server. Use the following commands in Server Core to complete the process, from installing the Docker to installing Microsoft IIS server:

Install-WindowsFeature Containers
Restart-Computer -Force
Invoke-WebRequest "https://download.docker.com/components/engine/windows-server/cs-1.12/docker.zip" -OutFile "C:\TEMP\dockerNew.zip" -UseBasicParsing
Expand-Archive -Path "C:\TEMP\dockerNew.zip" -DestinationPath C:\DockerFiles
$env:path += ";c:\dockerFiles"
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\DockerFiles", [EnvironmentVariableTarget]::Machine)
dockerd.exe --register-service
Start-Service docker
docker pull microsoft/nanoserver
docker run -d -p 80:80 microsoft/iis ping -t localhost

The first command above installs the Windows container feature inside the Server Core OS VM. Once the system finishes installing the container, reboot the Server Core to ensure container modules properly loaded during startup. The Invoke-WebRequest command invokes a request to obtain the container zip file from Docker and stores it in the C:\Temp\ folder. The next command unzips the contents of the DockerNew.zip file to C:\DockerFiles. You should make sure that you can execute the Docker command without encountering any errors by adding a path environment variable for C:\DockerFiles. The last four commands register Docker Engine with the Server Core OS, start Docker Engine, pull the Microsoft/Nano Server image and create a container with the Microsoft IIS server image.

The -d switch in docker run -d -p 80:80 microsoft/iis ping -t localhost command ensures that the system starts the container with a watchdog process. The watchdog process is required for Docker to monitor the container.

You might have noticed that the Microsoft IIS server image is based off the Server Core OS and think there is no need to download the image from Docker, but the Windows Server Core Docker image ships with the full set of Server roles and features. Once you download the Microsoft/Nano Server image, you must start Docker Engine with the Microsoft IIS server image to get a web server up and running inside the container.

Dig Deeper on Containers and virtualization

Software Quality
App Architecture
Cloud Computing
SearchAWS
TheServerSide.com
Data Center
Close