Share on Facebook0Share on Google+0Share on LinkedIn0Share on Reddit19Tweet about this on Twitter0

Docker logo

Image2Docker is a tool to convert some Windows Server roles to Docker containers (on Windows, for sure).

With this new version, it’s possible to extract ASP.NET website to run them in containers. To start, I created a VM with 3 ASP.NET websites. This is the view that I have from IIS Manager:

IIS Manager view

And the view from Internet Explorer:

ASP.NET Internet view

Here, we will migrate the WebApiApp website from Windows Server to Windows Container. To start, on the client/server that you’ll use to convert these sites, install the Image2Docker PowerShell Module:

PowerShell script

Following are rules that you can convert from Windows Server to Windows Containers:

PowerShell script

Now, copy the VHD or VHDX where your websites are stored. Execute the following command to extract all website of this VHDX:

PowerShell script

Argument ImagePath contains the path to your VHD/VHDX, the parameter OutputPath is the path where files will be copied and, finally, the parameter Artifact is IIS to specify to check the only website and nothing else. After few moments, your websites are extracted:

GlobalIIS root

As you can see, a Dockerfile appears. This file contains all parameters that are necessary to create a WindowsServerCore image in a container, add IIS features to execute ASP.NET website, copy sources in the right IIS folder of the container and finally, expose the port publicly:

Visual Studio view

I’ll now extract one site, by adding the ArtifactParam parameter, followed by the name of the website:

PowerShell script

Following is the Dockerfile associated, with this time, only one website. This is normal because I asked to extract only the WebApiApp website:

Dockerfile Visual Studio Code

We will now create the docker image based on this Dockerfile. To create the image, move to the folder where is stored the Dockerfile and execute the following command. You can modify the name of the image, which is in my case florentapp/webapiapp:

Command Prompt

StarWind HyperConverged Appliance is a turnkey, entirely software-defined hyperconverged platform purpose-built for intensive virtualization workloads. Bringing the desired performance and reducing downtime, the solution can be deployed by organizations with limited budgets and IT team resources. Also, it requires only one onsite node to deliver HA for your applications that make the solution even more cost-efficient.
Find out more about ➡  StarWind HyperConverged Appliance

Now, create a container from this image. For me, I’ll expose port 8080 that I link with the port 8080 of the website in my container. I’m giving a name to this container webapiapp. The command docker logs gives me the information about logs of the container, and especially the moment that the IIS service is started:

Command Prompt

After that, use the command docker inspect to find the IP address of your container to access the website:

Command Prompt

With Internet Explorer, you can access to your website which is in your container:

http://172.19.136.162:8080/

ASP.NET web view

On the server which executes the IIS container, you will have a new service running, w3wp, for each IIS container that will be created on this server.

I hope that this example and the script will help you to migrate quickly your websites to Windows Containers.

If you have any questions, don’t hesitate to ping me 🙂

Views All Time
14
Views Today
36
Appreciate how useful this article was to you?
1 vote, average: 2.00 out of 51 vote, average: 2.00 out of 51 vote, average: 2.00 out of 51 vote, average: 2.00 out of 51 vote, average: 2.00 out of 5
2 out of 5, based on 1 review
Loading...
Back to blog
The following two tabs change content below.
Florent Appointaire
Florent Appointaire is Microsoft Engineer with 5 years of experience, specialized in Cloud Technologies (Public/Hybrid/Private). He is a freelance consultant in Belgium from the beginning of 2017. He is MVP Cloud and Datacentre Management. He is MCSE Private Cloud and Hyper-V certified. His favorite products are SCVMM, SCOM, Windows Azure pack/Azure Stack and Microsoft Azure.