Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

[Docker] Image2Docker: Bye bye IIS on Windows Server, Hello IIS on Windows Containers

  • December 15, 2016
  • 6 min read
Cloud and Virtualization Architect. Florent is specializing in public, hybrid, and private cloud technologies. He is a Microsoft MVP in Cloud and Datacenter Management and an MCSE in Private Cloud.
Cloud and Virtualization Architect. Florent is specializing in public, hybrid, and private cloud technologies. He is a Microsoft MVP in Cloud and Datacenter Management and an MCSE in Private Cloud.

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

 

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 🙂

Found Florent’s article helpful? Looking for a reliable, high-performance, and cost-effective shared storage solution for your production cluster?
Dmytro Malynka
Dmytro Malynka StarWind Virtual SAN Product Manager
We’ve got you covered! StarWind Virtual SAN (VSAN) is specifically designed to provide highly-available shared storage for Hyper-V, vSphere, and KVM clusters. With StarWind VSAN, simplicity is key: utilize the local disks of your hypervisor hosts and create shared HA storage for your VMs. Interested in learning more? Book a short StarWind VSAN demo now and see it in action!