EasyHostingASP.NET | Best and cheap ASP.NET Core RC2 hosting. In this post how we can run and test an ASP.NET Core RC1 application. Yesterday RC2 was made public and it is now time to revisit the subject. This time we are going to create an ASP.NET Core RC2 MVC application, Docker-ize it and analyze how we can run and debug this application.

1install-rc2

Once you have installed RC2 please make sure to also install the Visual Studio Extension Docker Tools for Visual Studio 2015 – Preview that provides first class Docker support.

2docker-tools-for-vs1

Create an application

Start Visual Studio and create a new ASP.NET Web Core Web Application. Let’s call the solution HelloRC2 and the project Web. Select Web Application as template.

4select-template

So far so good. Let’s try to run this application locally on our developer machine. Select Web as target and press F5 to start the application. After compiling Visual Studio will start Kestrel (the new lightweight Microsoft Web Server) in a console window. It will also open a browser window at localhost:5000. By default Kestrel listens at port 5000.

If the browser reports an error This site can’t be reached then you might need to hit refresh since Kestrel was not starting up fast enough and thus was not ready to serve the request from the browser.

Wonderful, we have our ASP.NET Core application up and running. But this is not so exciting because it’s what we have done all the time… Thus let’s come to the more fascinating part, running the application in a Docker container.

Add Docker support

In the Solution Explorer right click on the Web project and select Add from the context menu. From the sub-menu select Docker Support. A folder called Docker will be added to our project containing a few interesting files. In addition to that the extension also adds two support files to the Properties folder. These are needed to provide the seamless integration of building, running and debugging Docker containers from within Visual Studio.

6docker-tooling

Run and debug the application

Make sure you select Docker as target

docker-as-target

Hit F5 to start the application. If you observe the Output window while the application is building you will notice that the script DockerTask.ps1 that was added to the Docker folder is executed. This script will do the following

  • build the application
  • publish the application
  • create a Docker image using the published application
  • create and run a container from the above image
  • start a browser page listening at [IP address] (where [IP address] corresponds to the IP address of your Docker host. In most cases this is 192.168.99.100)

As a result you should see your Web application running inside a container. The look and feel of the application in the browser is exactly the same as when we were running it directly on our developer machine

While building the container image the script has also added remote debugging support into the image. Thus we should be able to start a debugging session. Let’s do this now. Add a break point to line 18 of the HomeController. Now in the application select the About menu and observe how the debugger stops at the break point. We can now observe the content of variables or step through the code line by line – exactly the same way as we’re used when we’re debugging an application running directly on our developer box.

Summary

In this post I have demonstrated how we can create an ASP.NET Core RC2 MVC application, deploy the application into a Docker container and remote debug the application running in the container.

Alexia Pamelov

Alexia Pamelov

My name is Alexia Pamelov and I have spent the past 3 years building money making blogs review. Since then I have launched lots of successful nice blogs and after selling my survivalist blog I decided to teach other people how to do the same.
Alexia Pamelov