Running ASP.NET 5 Applications in Windows Containers with ContainerX

Last year at Build, Mark Russinovich showed an ASP.NET application running in a Linux container using the open sourced .NET runtime for Linux. Later in the year, last November Microsoft released Windows Server 2016 Technical Preview that has support for native Windows containers. Windows Server 2016 TP5 was released just a few weeks ago bundling a docker-engine for Windows and a host of other features.

In this post, I will show you how to run ASP.NET application in a native Windows container. Let’s get started!

Setup a Cluster and Pool

  1. If you haven’t installed ContainerX management server, get your free version.
  2. Setup a Windows Server 2016 cluster on Azure using ContainerX. Follow the instructions here. Using the instructions, create a cluster with two hosts and create a single pool with CPU and Memory limits set to 100%. To learn more about clusters and pools, see here.
  3. Now that you have a Windows cluster and pool, download the credentials to access the pool.Screen Shot 2016-06-29 at 9.41.48 AM.png

Install Docker for Windows

  1. Before, you can use the credentials, install Docker for Windows by following the instructions here.
  2. Unzip the credentials file and run the command
    env.cmd
  3. Run docker to verify that Docker installation is successful and you are able to access the poolScreen Shot 2016-06-29 at 10.04.49 AM

Create an ASP.NET app in Visual Studio

We are ready to write a sample ASP.NET app now. Start with a new project from Visual Studio (if you don’t have VS installed, get the free community version).

Screen Shot 2016-06-29 at 10.22.04 AM

Screen Shot 2016-06-29 at 10.22.30 AM

Modify the project.json to run on all interfaces so that we can access the ASP.NET app externally. Otherwise, by default the app will be running on localhost:5000Screen Shot 2016-06-29 at 12.03.50 PM

 

Build a Docker Image and Run

We are going to write a Dockerfile that builds the Docker image for this app. Change to the directory, where the project’s src directory. On my system, it is C:\Users\ppadala\Documents\Visual Studio 2015\Projects\WebApplication1\src. Open a text editor, enter the following and save it as Dockerfile.

FROM microsoft/aspnet

COPY . /
WORKDIR /WebApplication1

ENTRYPOINT powershell

Build the image with the following command

docker build -t myapp .

Run the container

docker run -p 5000:5000 -it myapp

You will be placed in powershell inside the container. Run the following command to start the ASP.NET app

dnu restore
dnx web

 

Access the ASP.NET app

Find where the container is running by going to ContainerX UI

Screen Shot 2016-06-29 at 2.25.53 PM.png

Open port 5000 of the host VM (in this example, cxHost-4300) in Azure portal

Screen Shot 2016-06-29 at 11.01.11 AM

Access the ASP.NET app with http://<ip address of host>:5000. Viola! Your first ASP.NET app in a Windows native container!

Screen Shot 2016-06-29 at 12.30.19 PM.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s