Docker makes application deployment easier than ever before. However, most of the Docker articles are often written how to containerized application that runs on Linux boxes. But since Microsoft now released windows containers, the legacy (yes, we can consider .net 4.5 as legacy apps) .net web apps are not left out anymore. I was playing with an ASP.net 4.5 web application recently, trying to make a container out of it. I have found the possibility exciting, not to mentioned that I have enjoyed the process entirely. There are few blogs that I have found very useful, especially this article on FluentBytes. I have however, developed my own scripts for my own application, which is indifferent than the one in FluentBytes (thanks to the author), but I have combined few steps into the dockerfile – that helped me get going with my own containers.
If you are reading this and trying to build container for your asp.net 4.5 applications, here are the steps: In order to explain the process, we’ll assume our application is called LegacyApp. A typical asp.net 4.5 application.
- We will install Docker host on windows.
- Create a directory (i.e. C:\package) that will contain all the files needed to build the container.
- Create the web deploy package of the project from Visual studio. The following images hints the steps we need to follow.
Image: Create a new publish profile
Image: Use ‘Web Deploy Package’ option
Important note: We should name the site in the following format Default Web Site\LegacyApp to avoid more configuration works.
- Download the WebDeploy_2_10_amd64_en-US.msi from Microsoft web site
- I have ran into an ACL issue while deploying the application. Thanks to the author of FluentBytesarticle, that provides one way to solve the issue by using a powershell file during the installation. We will create that file into the same directory, let’s name it as fixAcls.ps1. The content of the file can be found here
- We will create the dockerfile into the same directory, with the content of this sample dockerfile
At this moment our package directory will look somewhat following:
- Now we will go to the command prompt and navigate the command prompt to the directory (i.e. C:\package) we worked so far.
- Build the container
c:/> docker build -t legacyappcontainer .
- Run the container
c:/> docker run -p 80:80 legacyappcontainer
Now that the container is running, we can start browsing your application. we can’t use the localhost or 127.0.0.0 on our host machine to browse the application (unlike Linux containers), we need to use the machine name or the IP address in our URL. Here’s what we can do:
- We will run the inspect command to see the container IP.
C:\> docker -inspect
- Now we will take the IP from the JSON and use the IP on our URL to navigate to the application.
The complete dockerfile can be found into the Github Repo.