Build a Docker Image from ASP.NET 4.5 Published Files

Containerization is often associated with modern .NET (Starting from Core/5+), but many enterprise applications still run on ASP.NET 4.5 / .NET Framework. These legacy apps can also be containerized using Windows-based Docker images, enabling easier deployment, consistency across environments, and simplified scaling.

This article walks through how to build a Docker image from ASP.NET 4.5 published files step by step.

Prerequisites

Before starting, ensure you have the following:
  • Windows 10/11 Pro or Windows Server
  • Docker Desktop installed
  • Windows Containers enabled
  • ASP.NET 4.5 published folder
Note:- ASP.NET 4.5 requires Windows containers (Linux containers are not compatible).

Install Docker Desktop (Recommended for Development)

If Docker Desktop is not installed on your machine, you must install and configure Docker before building the ASP.NET 4.5 container image.

  1. Download Docker Desktop from the official Docker website.
  2. Run the installer and follow the setup wizard.
  3. Restart your machine if prompted.
  4. Launch Docker Desktop after installation.
  5. Switch to Windows Containers mode:
    • Right-click the Docker icon in the system tray.
    • Select Switch to Windows Containers.
  6. Verify the installation by running:
    
      	docker --version
    	docker ps
    
    

If Docker is installed correctly, the commands will return the Docker version and a list of running containers.

Verify Windows Container Support

Since ASP.NET 4.5 applications run on the .NET Framework, they require Windows containers rather than Linux containers. Confirm that Docker is running in Windows container mode before building the image:


	docker info

Look for information indicating that Windows containers are enabled.

Once Docker is installed and configured, proceed with publishing the ASP.NET 4.5 application and building the Docker image as described in the next sections.

Use a Windows Server with Docker Engine

In enterprise environments, Docker Desktop may not be allowed due to licensing or organizational policies. In this case, you can install Docker Engine directly on a Windows Server host.

  1. Install the Containers feature:
     
          Install-WindowsFeature -Name Containers
          
  2. Install-WindowsFeature -Name Containers
  3. Restart the server.
  4. Install Docker Engine using Microsoft's installation instructions.
  5. Verify the installation:
      
    docker version
      

Publish the ASP.NET 4.5 Application

First, publish your application from Visual Studio if not published:
  1. Right-click your project in Visual Studio
  2. Click Publish
  3. Choose Folder as the target
  4. Select a location like:
      
    C:\publish\MyWebApp
      
  5. Click Publish
You should now have:
  • .aspx / .cshtml files
  • bin folder
  • web.config
  • static assets

Choose a Base Docker Image

For ASP.NET 4.5, you typically use:
  	
    mcr.microsoft.com/dotnet/framework/aspnet
  
This image includes:
  • IIS
  • ASP.NET runtime
  • .NET Framework support

Create a Dockerfile

Inside your published folder (or a separate build directory), create a file named:
  
    Dockerfile
  
Example Dockerfile:
  
	
    # Use ASP.NET 4.8 (compatible with 4.5 apps in most cases)
	FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019

	# Set working directory inside container IIS site root
	WORKDIR /inetpub/wwwroot

	# Copy published files into container
	COPY ./publish/ .

	# Optional: expose HTTP port
	EXPOSE 80

  

Understanding the Dockerfile

The Dockerfile defines how the Docker image is built and how the ASP.NET application is hosted inside the container.

FROM

The FROM instruction specifies the base image used to create the container.

This image includes:
  • Windows Server Core operating system
  • Internet Information Services (IIS)
  • ASP.NET runtime
  • .NET Framework 4.8

Although the application was developed using ASP.NET 4.5, most ASP.NET 4.5 applications run successfully on the .NET Framework 4.8 runtime because Microsoft maintains a high level of backward compatibility across .NET Framework versions.

WORKDIR

The WORKDIR instruction sets the default working directory for subsequent commands.

/inetpub/wwwroot is the default IIS website root directory inside the container. By setting this directory as the working location, all copied files are placed directly into the IIS website folder.

Equivalent Windows path:
  
  C:\inetpub\wwwroot

COPY

The COPY instruction transfers files from the local machine into the Docker image.

Source:
  
  C:\inetpub\wwwroot

Destination:
  
  /inetpub/wwwroot

When the image is built, all published application files such as:
  • Web.config
  • Bin folder
  • ASPX pages
  • MVC Views
  • JavaScript files
  • CSS files
  • Images

are copied into the IIS web root, making them available to the web server when the container starts.

For example:
  
	Host Machine 
  	└── publish 
    ├── bin 
    ├── Views 
    ├── Content 
    └── Web.config 
    
    Container 
    └── C:\inetpub\wwwroot 
    ├── bin 
    ├── Views 
    ├── Content 
    └── Web.config

EXPOSE

The EXPOSE instruction documents that the container listens for HTTP traffic on port 80. Port 80 is the default port used by IIS for HTTP requests.

When running the container, you can map a host port to container port 80:
  
docker run -d -p 8080:80 my-aspnet-app  

In this example:
  • 8080 = Host machine port
  • 80 = Container IIS port
Users access the application through:
  
	http://localhost:8080

Docker forwards requests from port 8080 on the host machine to port 80 inside the container.

Note: EXPOSE does not actually publish the port. Port publishing occurs when the container is started using the -p option.

Build the Docker Image

Run the following command from the directory containing your Dockerfile:
  
	docker build -t aspnet45-app .

This will:
  • Pull the base Windows IIS image
  • Copy your published files
  • Create a reusable image

Run the Container

Start a container using:
  
	docker run -d -p 8080:80 --name my-aspnet-app aspnet45-app

Now open in browser:
  
	http://localhost:8080

Your ASP.NET 4.5 application should be running inside a containerized IIS environment.

Common Issues & Fixes

  1. Port not accessible
    • Ensure Windows Firewall allows port 8080
    • Confirm container is running using:
        
      	docker ps
      

  2. HTTP Error 500
    • Check IIS logs inside container
    • Ensure all required DLLs are in bin folder
  3. Wrong base image
    • Always use Windows Server Core images
    • Match Docker host OS version compatibility
  4. Optimizing the Docker Image
    • Remove unnecessary files before copying
    • Use multi-stage builds (if building inside Docker)
    • Enable compression in IIS
    • Exclude debug symbols (.pdb files)

Recommended Improvements (Production Use)

  • Use a specific Windows Server Core LTSC version matching your host
  • Use multi-stage builds (if building inside container)
  • Externalize configs (appsettings, connection strings)
  • Use environment variables for configuration

Summary

Containerizing ASP.NET 4.5 applications is a practical way to modernize legacy systems without rewriting them. With Windows containers and IIS-based images, you can package your published web app into a portable Docker image and deploy it consistently anywhere Docker runs.

Thanks

Kailash Chandra Behera

I am an IT professional with over 13 years of experience in the full software development life cycle for Windows, services, and web-based applications using Microsoft .NET technologies.

Previous Post Next Post

نموذج الاتصال