Breathing new life into aging yet critical .NET 3.5 applications is now more achievable than ever through containerization. This guide provides a comprehensive, step-by-step approach to packaging your legacy applications into portable and efficient Docker containers, paving the way for improved deployment, scalability, and a longer operational lifespan.

Prerequisites

  • Docker Desktop for Windows: Make sure it is configured to use Windows Containers. You can switch between Linux and Windows containers by right-clicking the Docker icon in the system tray.
  • Your .NET 3.5 Application Source Code

Why Containerize Your .NET 3.5 App?

The benefits of containerizing the app is simplified deployment, enhanced portability, improved scalability, increased isolation, consistent environments, and foundation for microservices…

Example App

You can clone this repository for testing or use your own app, https://github.com/man20820/dotnet-container-example or https://github.com/microsoft/dotnet-framework-docker-samples/tree/master

Dockerfile

The Dockerfile is the blueprint for building your Docker image. It’s a text file that contains a series of commands and instructions that Docker follows to assemble your application and its environment.

Example Dockerfile for .NET 3.5 web application.

FROM mcr.microsoft.com/dotnet/framework/sdk:3.5 AS build-env
WORKDIR /src

COPY dotnetapp-3.5.sln .

COPY dotnetapp-3.5/ ./dotnetapp-3.5/

RUN msbuild dotnetapp-3.5.sln /p:Configuration=Release /p:TargetFrameworkVersion=v3.5

FROM mcr.microsoft.com/windows/servercore:ltsc2022

RUN powershell.exe -Command \
    Set-Service -Name wuauserv -StartupType Automatic -ErrorAction SilentlyContinue; \
    Start-Service -Name wuauserv -ErrorAction SilentlyContinue -PassThru; \
    Set-Service -Name BITS -StartupType Automatic -ErrorAction SilentlyContinue; \
    Start-Service -Name BITS -ErrorAction SilentlyContinue -PassThru; \
    Add-WindowsFeature NET-Framework-Core

WORKDIR /app

COPY --from=build-env /src/dotnetapp-3.5/bin/Release .

RUN dir

CMD ["MyDotNet35App.exe"]

Build the Dockerfile

With your Dockerfile in place, open a command prompt or PowerShell in the root directory of your project and follow these steps:

docker build -t <tag> .

(Optional) Push to container registry

if you have container registry, you can tag your image to use the container registry… in this article im using azure container registry and push the image to registry. you can skip this step if you don’t have

Test / Run your container

docker run -d --name dotner35 -p 80:80 <tag>

This example app is listen http on port 80, you can access using web browser to localhost/info

Thank you