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

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 Studoi 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 promt

StarWind HyperConverged Appliance is a turnkey hyper-converged hardware platform fitted into a small two-node footprint. You don’t need anything else to build a budget-friendly new IT infrastructure or upgrade an existing one. All your systems will be “babysitted” by StarWind 24/7/365, troubleshooting any concerns without your involvement. Everything’s operated through a neat web UI. We’ll also migrate your workloads at no extra cost.

Dramatically decrease your CapEx, OpEx, and IT management costs, while visibly increasing return on investment (ROI) with hyperconvergence for ROBO, SMB & Edge from StarWind.

 

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 🙂

Back to blog