Windows Server Summit 2024
Mar 26 2024 08:00 AM - Mar 28 2024 03:30 PM (PDT)
Microsoft Tech Community
Modernize your IT environment and applications with Windows Containers
Published Nov 07 2019 05:47 AM 3,450 Views

This is Ignite week and part of the team is in Orlando talking to customers and delivering sessions. It's amazing to see the enthusiasm on Windows Containers with more and more people stopping by to ask how they can get started and how they can containerize their first application.

That's why Craig and I are doing a session today called "Modernize your IT environment and applications with Windows Containers". The idea of this blog post is to server as a reference blog for that session, with all the instructions for the demos we presented today.

During the session we cover how you can containerize an ASP.Net 3.5 web application running on Windows Server 2008 R2 with Windows containers on Windows Server 2019.

 

Test proofing your application on Windows Server 2019

Before we get into the containers portion, it's important to understand how your application behaves, what are its components, and how you can validate that the application actually runs on Windows Server 2019 - or at least Windows Server 2016 for that matter - so you know it will work in a container.

In order to do that, you'll have to check how do you deploy that application. For our case, since this is a web application running on IIS, you have a few options:

  • If you have access to the source code, you should probably work with the dev team to containerize the application directly from Visual Studio. Visual Studio has all the tooling embedded to create a container image with your application on it.
  • If you have a package with your application, you need the instructions on how to deploy this. Traditionally, developers will provide minimal instructions on how to deploy the application and you can leverage that.
  • If the application is already deployed, you need a way to extract the application from the current server. For web applications on IIS there are, thankfully, a couple options here. You could simply export the applications using native IIS commands from command prompt. Another option is to use Web Deploy to export the application into a Zip file that can be used to import the application on the other side.

Once you have your strategy to get the application from the current server to the new Windows Server 2016 or 2019, you can deploy the application and validate it runs fine.

 

Containerizing your application

The process to containerize the application is a bit different than most admins are used to with VMs. With VMs you deploy an OS, than the app dependencies, than the app, and finally you configure the app. Often times, all manually. After all that, you generalize the image with Sysprep and store the VHD file in a place that consumers of this app can deploy a new VM.

With containers, you actually declare how your application will be composed in a Docker file (which is just a text file called dockerfile - no extension - in the same folder you have your application.

The Docker file provides the instructions for the command "docker build" to build your application and store it in a container.

Here's the example of the docker file Craig and I used in our session today:

FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019
WORKDIR /ViniBeer
COPY . .
RUN PowerShell Install-WindowsFeature NET-Framework-45-ASPNET; \
	Install-WindowsFeature Web-Asp-Net45
RUN PowerShell Import-Module WebAdministration; \
	New-WebApplication "ViniBeer" -Site 'Default Web Site' -ApplicationPool "DefaultAppPool" -PhysicalPath "C:\ViniBeer"

From top to bottom, here's what you should know about the above:

  • FROM: This is where you start your application from. There are multiple container images available in the Docker Hub, so instead of deploying Windows components, you can most probably find an image that already has what you need to deploy your app. In this case, we're starting with the IIS container image that has IIS pre-installed.
  • WORKDIR: This is your working directory. It assumes the context of the C:\ drive, so in the case above it will create a new folder at C:\ViniBeer and set that folder as the working directory. Throughout the file, you can simply reference this folder with a ".".
  • COPY: As the name says, this will copy content into the container. The way the context work here is the first path is the local container host from which you are running docker build. The second path is the path inside the container. In our case, we're copying the content from the folder we're running docker build to the C:\ViniBeer working directory we referenced earlier.
  • RUN: Run will execute commands inside the container to get it prepared. The example above is using PowerShell and then the commands to run on it. The first one deploys the ASP.Net IIS dependencies and the second one imports the IIS PowerShell module to then install the web application - just like you would do in a regular Windows Server with Server Core.

The docker build command you run to execute all this is:

docker build -t vinibeerimage .

This will tag the image as "vinibeerimage" and store the image locally. Now all you have to do is deploy new containers based on that container image.

 

Try it yourself with our Vini Beer sample app.

If you want to try the exact same demo we ran in our session at Microsoft Ignite, you can use the Vini Beer sample ASP.Net 3.5 app that was running in a Windows Server 2008 R2 machine. The app is stored in this GitHub repository - along with the docker file above.

The recording for the session will be available later today.

 

We hope this helps in your containerization journey!

Version history
Last update:
‎Nov 07 2019 05:47 AM
Updated by: