Wrapping an ASP.NET web application to a Docker container

Posted: (EET/GMT+2)

 

You can run a classic ASP.NET (full .NET Framework) web application in Docker using Windows containers and IIS. The container holds IIS, the .NET Framework, and your application, so you can move it between compatible Windows hosts.

A minimal Dockerfile might look like this:

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.7.2-windowsservercore-ltsc2016
WORKDIR /inetpub/wwwroot
COPY . .

With this "Dockerfile" in place, do the following:

  1. Publish your ASP.NET app from Visual Studio to a folder (File System publish).
  2. Place the above Dockerfile next to the published files.
  3. Build the image:
docker build -t my-aspnet-app .
  1. Run a container mapping host port 8080 to container port 80:
docker run -it --rm -p 8080:80 my-aspnet-app

Now you can browse to http://localhost:8080/ and see your application running inside the container.

For new applications, ASP.NET Core is often a better fit with Linux containers, but if you have existing ASP.NET applications you want to package and move around more easily, wrapping them in a Windows Docker container is a great first step.