Containerised IIS Application To Windows Container

Containerised IIS Application to Windows Container

In this blog, we will show you the steps to containerised IIS Application to Windows Container in Windows 2016.

REQUIREMENTS

  • VHD (or) VHDX image with IIS role & ASP.NET application.
  • Container host with Decker role installed.
  • Any machine with Windows 2012, 2012 R2 (or) 2016 to run the image conversion tool.

PREPARING VHD (or) VHDX IMAGE

Note: In this demo, we are using windows 2008 VM along with .NET 4.5.2 and IIS service Installed.

  • We have installed IIS service and hosted a Test ASP.NET Application.
Convert IIS Application VM to windows Container
  • We are able to access the test application using the server IP without any problem.
Convert IIS Application VM to windows Container
  • Copy the server VHD file to a separate location for the conversion process.

Note : For this demo, we are using windows 2016 machine to run the image conversion process. You can also using windows 2012 with powershell version 5.0.

  • We create a folder named VHD in C:\ drive and copy the VHD files into that folder.
Convert IIS Application VM to windows Container

INSTALLING IMAGE CONVERSION TOOL

  • Open the PowerShell window and execute the below command.

Install-Module -Name Image2Docker

Convert IIS Application VM to windows Container

Note : This is tool is still under development. You can find the latest version of this tool from this URL : https://www.powershellgallery.com/packages/Image2Docker/1.8.2.

CUSTOMIZE THE IMAGE2DOCKER MODULE

  • We need to make minor changes in the image2docker template file to make the ASP.NET application workable.
  • To Find the installed path of image2docker module, execute the below command from the PowerShell window.

($PSModPath=gmo -l).path

Convert IIS Application VM to windows Container
  • Go to C:\Program Files\WindowsPowerShell\Modules\Image2Docker\1.8.2\Resources folder.
Convert IIS Application VM to windows Container
  • Double click on Dockerfile-ASPNET-35.template file and add the below lines.

# Install Web Server Components
RUN Install-WindowsFeature -name web-app-dev –IncludeAllSubFeature

Convert IIS Application VM to windows Container
  • Save the file and close it.

EXECUTING IMAGE2DOCKER

  • Once you installed and customize the image2docker module, open the PowerShell window and execute the below command to extract all the website from IIS and its configuration.

SYNTAX: ConvertTo-Dockerfile -ImagePath <VHD path> -OutputPath <path to save the IIS configuration> -Artifact IIS –Verbose

COMMAND : ConvertTo-Dockerfile -ImagePath C:\VHD\Conttest.vhdx -OutputPath C:\VHD\conttest -Artifact IIS –Verbose

Convert IIS Application VM to windows Container
  • Open C:\VHD\conttest folder and verify the website configuration files.
Convert IIS Application VM to windows Container
  • Open the dockerfile and verify our customize entry was added in the docker file.
Convert IIS Application VM to windows Container

IMPORT IIS FILES TO CONTAINER HOST

  • Login into container host machine and access the conttest folder through a network share.

\\192.168.232.17\c$\VHD

Note : This is our lab setup. So the IP might vary based on your environment

Convert IIS Application VM to windows Container
  • Copy the conttest folder from the shared location to the container host local drive.
Convert IIS Application VM to windows Container

BUILDING THE CONTAINER

  • Open the PowerShell window and execute the below command to build a container.

docker build -t conttest c:\conttest

Convert IIS Application VM to windows Container
  • It will take few minutes to complete the container building process.
Convert IIS Application VM to windows Container
  • Once the build completed successfully. Type docker images command to verify the image.
Convert IIS Application VM to windows Container

VERIFYING THE CONTAINER

  • From the PowerShell window, type the below command to create a new container in detach mode.

SYNTAX: docker run –d <container image name>

COMMAND: docker run –d conttest

Convert IIS Application VM to windows Container
  • Type docker ps to verify the container name
Convert IIS Application VM to windows Container
  • To find the IP address of the container uses the below command.

SYNTAX: docker inspect <container ID>

COMMAND: docker inspect d4

Convert IIS Application VM to windows Container
Convert IIS Application VM to windows Container
  • Browse the IP 172.28.238.72 from the container host and verify the ASP.NET application.
Convert IIS Application VM to windows Container
VIDEO

Thanks for reading this blog. We hope it was useful for you to learn how to convert the IIS application VM to Docker container.

Loges