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
- If you haven’t installed ContainerX management server, get your free version.
- 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.
- Now that you have a Windows cluster and pool, download the credentials to access the pool.
Install Docker for Windows
- Before, you can use the credentials, install Docker for Windows by following the instructions here.
- Unzip the credentials file and run the command
- Run docker to verify that Docker installation is successful and you are able to access the pool
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).
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:5000
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
Open port 5000 of the host VM (in this example, cxHost-4300) in Azure portal
Access the ASP.NET app with http://<ip address of host>:5000. Viola! Your first ASP.NET app in a Windows native container!