App Dev Manager Farah Deendar explores first steps of application modernization through simple containerization.
As an Application Development Manager, I often have conversations with my enterprise customers around application modernization, its synonymy with containers and microservices and what is the best way to modernize line of business applications. Many enterprise organizations today have numerous desktop applications that are CRUD based and call for modernization without necessarily needing to re-architect these LOB legacy apps. Web Apps on traditional .NET framework, ASP.NET web forms, MVC or WCF apps are common examples. If you have an existing .NET enterprise application that could use CI/CD but not necessarily any immediate rearchitecting efforts containerizing your application is the way to go. Although the role of Domain Design Modeling and use of Microservices is vital to modernizing Enterprise Architecture and applications, it does not always make business sense to rearchitect a legacy application.
The focus of this blog is to help developers in the enterprise to containerize existing .NET Framework applications/services that currently need to run on Windows. I will be using Windows Containers for the rest of this blog. The windows containers can be run at scale with Azure containers as an option with many benefits. If you don’t want to move to the cloud, you can apply these approaches on-premises, too.
Steps to containerize a windows Desktop application:
- Pre-requisites for a working Environment:
- Windows 10 Enterprise/Pro with Hyper-V enabled
- Docker for Windows. The full list of pre-req’s is available here.
- Command Shell or PowerShell for windows
- Visual Studio 2017, ASP.NET/MVC/WCF app Note: To get things working via Windows, select the option “Switch to Windows containers” in the Docker tray icon. See below: Note: Docker for Windows after install defaults to Linux containers.
- Asp.net Desktop application: For the purposes of this blog, the containerization sample ASP.NET application used is available here. You can use your existing .net app in place of this sample and follow the steps provided in the sample and/or below:
- Containerize your application.
- Navigate to your local project directory and create the docker file. The key to containerizing your application is building your Dockerfile.
A docker file is a text document that contains all the commands to build your container image. More details on Dockerfile are available here.
Below PowerShell command you will use to create the dockerfile in your project root folder:
New-Item C:/YourProjLocation/Dockerfile -type file
- Next you will add logic to your Dockerfile that declares which base image you will use to build your container.
See writing to your Dockerfile as an example or below
PowerShell Command:
FROM microsoft/aspnetcore-build:1.1 AS build-env
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM microsoft/aspnetcore:1.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "MvcMovie.dll"]
- Now you will tell docker to build your app and run the container.
PowerShell command:
docker build -t myapp
docker run -d -p 5000:80 --name myapp myasp
Note: Your powershell console’s current working directory needs to be pointing to where your dockerfile resides. - Get the IP address of your running container using the command below
PowerShell Command
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" myapp
- Copy the IP address to your local web browser. You have successfully containerized your ASP.NET application!
- Navigate to your local project directory and create the docker file. The key to containerizing your application is building your Dockerfile.
A docker file is a text document that contains all the commands to build your container image. More details on Dockerfile are available here.
Below PowerShell command you will use to create the dockerfile in your project root folder:
Resources to help Scale your containers on premises:
Docker hosts with Windows Containers on Windows Server 2016. VMs/Servers can be on-premises. For your orchestration needs Azure Service Fabric can be on-premises as well as Kubernetes can be on-premises.
Resources to help Scale and run your Containers in the Cloud:
Containerizing monolithic applications in Azure
Azure Service Fabric
https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-containers-overview
Container Orchestration in the Cloud
Container orchestrators are assigned a pool of servers (VMs or bare metal servers), commonly called a “cluster,” and “schedule” deployment of containers onto those servers. Some orchestrators go further and configure networking between containers on different servers, while some include load balancing, container name resolution, rolling updates and more. Some are extensible and enable application frameworks to bring these additional capabilities. While a deeper discussion on orchestration solutions might require a whole other post on its own, here’s a quick outline a few of the technologies, all supported on top of Azure:
- Docker Compose enables the definition of simple multi-container applications. Docker Swarm manages and organizes Docker containers across multiple hosts via the same API used by a single Docker host. Swarm and Compose come together to offer a complete orchestration technology built by Docker.
- Mesos is an orchestration and management solution that actually predates Docker, but has recently added support for Docker into its built-in application framework Marathon. It is an open and community-driven solution built by Mesosphere. We recently demonstrated integration with Mesos and DCOS on Azure.
- Kubernetes is an open-source solution built by Google offering container grouping into “Pods” for management across multiple hosts. This is also supported on Azure.
- Deis is an open source PaaS platform to deploy and manage applications integrated with Docker. We have an easy way to deploy a Deis cluster on Azure.
Premier Support for Developers can help with your organizational readiness and deployment of Enterprise Application Modernization. For more information go here or please contact Farah Deendar.
0 comments