Deploying an Old ASP.NET MVC 2 Application with SQL Server Using Windows Containers
This tutorial demonstrates how to containerize a legacy ASP.NET MVC 2 web application with a SQL Server database by running a Windows Container, configuring volume mappings, updating connection strings, creating a Dockerfile, building an image, and deploying the service.
In a previous article we showed how to run a modern .NET 4.5 web app in a Windows Container; this guide revisits the scenario with a much older 2010 project built on ASP.NET MVC 2 and SQL Server, illustrating that even legacy applications can be containerized.
The solution is first imported into Visual Studio 2017 and upgraded without errors. To provide the required database, a SQL Server Express container is started using Docker.
docker run -d -p 1433:1433 -e sa_password=P2ssw0rd -e ACCEPT_EULA=Y -v c:\temp:c:\temp --name sql harbor-bj.devopshub.cn/microsoft/mssql-server-windows-express
Volume mapping (c:\temp on the host to c:\temp in the container) allows the MDF file to be placed on the host and attached inside the container. The container's IP address is obtained with:
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" sql
Using SQL Server Management Studio, the container is connected with the retrieved IP and the SA password defined above. The database MDF file is copied to the host's c:\temp directory and attached through the SSMS interface, which now points to the container's file system thanks to the volume mapping.
The project's web.config is edited so that its ConnectionString points to the SQL Server instance running in the container.
A Dockerfile.windows is added to the project with the following content:
FROM harbor-bj.devopshub.cn/microsoft/iis SHELL ["powershell"] RUN Install-WindowsFeature Net-Framework-45-ASPNET ; \ Install-WindowsFeature Web-Asp-Net45 ARG source=. WORKDIR 'c:\app' RUN Remove-Website -Name 'Default Web Site' RUN New-Website -Name 'aspnet45docker' -Port 80 \ -PhysicalPath 'c:\app' -ApplicationPool '.NET v4.5' EXPOSE 80 COPY $source .
The image is built with:
docker build -f Dockerfile.windows -t tailspintoys:win-v1 .
After a successful build, the container is run and its IP address retrieved:
docker run -itd -p 81:80 --name tp tailspintoys:win-v1 docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" tp
The source code for the demo project is available on GitHub at https://github.com/lean-soft/TailspinToys-docker , allowing readers to try the steps themselves.
Related article: Docker4Dev #6 Using Windows Container to Run .NET Applications
--- Promotional Section (non‑academic) ---
Recommended Training: "Docker‑based DevOps Practical Training" by instructor Xu Lei, a three‑day closed‑course held in Beijing from March 24‑26, 2017. For details and registration, click the original article link.
DevOps
Share premium content and events on trends, applications, and practices in development efficiency, AI and related technologies. The IDCF International DevOps Coach Federation trains end‑to‑end development‑efficiency talent, linking high‑performance organizations and individuals to achieve excellence.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.