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.
- 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.
- We are able to access the test application using the server IP without any problem.
- 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.
INSTALLING IMAGE CONVERSION TOOL
- Open the PowerShell window and execute the below command.
Install-Module -Name Image2Docker
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.
- Go to C:\Program Files\WindowsPowerShell\Modules\Image2Docker\1.8.2\Resources folder.
- 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
- Save the file and close it.
- 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
- Open C:\VHD\conttest folder and verify the website configuration files.
- Open the dockerfile and verify our customize entry was added in the docker file.
IMPORT IIS FILES TO CONTAINER HOST
- Login into container host machine and access the conttest folder through a network share.
Note : This is our lab setup. So the IP might vary based on your environment
- Copy the conttest folder from the shared location to the container host local drive.
BUILDING THE CONTAINER
- Open the PowerShell window and execute the below command to build a container.
docker build -t conttest c:\conttest
- It will take few minutes to complete the container building process.
- Once the build completed successfully. Type docker images command to verify the image.
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
- Type docker ps to verify the container name
- To find the IP address of the container uses the below command.
SYNTAX: docker inspect <container ID>
COMMAND: docker inspect d4
- Browse the IP 172.28.238.72 from the container host and verify the ASP.NET application.
Thanks for reading this blog. We hope it was useful for you to learn how to convert the IIS application VM to Docker container.