Technologieplauscherl - .NET on Linux, Docker, and Azure

20 August 2015 - .NET, Azure, C#


Today I will do a session at a local user group called Technologieplauscherl. It is an informal meeting of people interested in technology. The topic I am going to speak about is Microsoft .NET and its new relationship with Linux, open source, and Docker. In this blog article I provide important links and the sample code I am going to show so that the attendees can follow along or play with .NET on Linux at home using this article as a starting point.

Microsoft .NET and Linux - What has Changed?

I have been working with .NET for decades. Until recently, .NET has meant you had to use Windows. With the rise of the cloud (in particular Microsoft's Azure cloud), Microsoft started to really embrace the idea of open source. Additionally, Microsoft started to fall in love with the idea of platform independence. Some people thought that this is just an episode - but in the last months, Microsoft has proven that they are serious. Here are some examples:

  • Microsoft is developing an open source and platform-independent version of their .NET Framework (CoreCLR).
  • More and more parts of the .NET Framework follow (e.g. Entity Framework, ASP.NET, etc.), they are now open source projects on Github.
  • Microsoft rewrote their entire C# and VB.NET compiler platform (codname Roslyn) and made it open source and platform independent.
  • Each and every SDK for Microsoft Azure is open source.
  • All the projects mentioned above are accepting commits from the community.
  • ...

If you want to dive deeper into C#, .NET & Co., here are some important links:


Visit the Github site of the CoreCLR. You will find links and installation instructions there. Note that at the time of writing, the CoreCLR is still not stable yet. You should not use it for production yet. Also note that you will need to install Mono to play with the CoreCLR. This is a temporary requirement that will disapear in the future.


At Technologieplauscherl, I will demo ASP.NET web applications, too. If you want to learn more about ASP.NET 5, the first open source and platform-independent version of ASP.NET, visit its Github repository.

Visual Studio Code

Microsoft has not only made the runtime, framework, and compilers platform-independent, they also created a light version of its development environment Visual Studio available on all platforms (MacOS, Linux and Windows). They called it Visual Studio CodeCode is not only an editor. It uses Omnisharp to provide IntelliSense, syntax highlighting, refactoring, etc. At Technologieplauscherl, I use Code for developing my C# demos on Ubuntu.

Demo 1 - .NET Basics

My first demo demonstrates the basics. I prepared the following setup:

If you want to try the sample I show at Technologieplauscherl, here is my story book for the demo:

  • Open a terminal window on your Linux box.
  • Use dnvm, the .NET version manager, to install the .NET runtime you would like to use. For my demos I will use Mono as the CoreCLR is still too unstable. If you read that in a few months, you will probably be able to use the CoreCLR version already.
  • Run yo aspnet and create a console application.
  • Use Code to open the folder with the console app and make yourself familiar with the code.
  • Run dnu restore in the folder with the console app to restore the library that the app depends on.
  • Run dnx . run to execute your console app. You should see Hello World.

Voila, .NET on Linux :-)

Demo 2 - Web Application

Next, we want to try a more complex program, an ASP.NET web application with server- and client-side code:

  • Run yo aspnet and create a Web Application Basic.
  • Use Code to open the folder with the console app and make yourself familiar with the code.
  • Run dnu restore in the folder with the console app to restore the library that the app depends on.
  • Run dnx . kestrel (kestrel is the name of the web server we are using) to execute the server-part of the app.
  • Use your web browser to open http://localhost:5000/. You should see the ASP.NET web application

Demo 3 - Using Docker on Azure

If you tried the samples shown above yourself, you have seen that setting up your Linux box to run ASP.NET is not super simple. You can use Docker to make your life easier.

If you are not familiar with Docker, take a look at my intro video on Channel9.

Microsoft has a partnership with Docker and offers a ready-made image for running ASP.NET applications. You don't even have to setup Docker on your machine. In Azure, Microsoft provides a ready-made Linux image with Docker installed and configured.

  • Create an Ubuntu VM with Docker in Azure.
  • Connect to the VM (on Windows, I use PuTTY for that).
  • Try if Docker is ready to use by running docker info.
  • Compress the web app you created on your local Linux box before using tar cfzv web.tar *.
  • Use scp to copy the tar-file to your VM in the cloud (you have to change the following command according to your username, machine name, and paths): scp web.tar
  • Extract the web app on your VM in the cloud using tar xfv web.tar.
  • Start a Docker container for ASP.NET using Microsoft's pre-built Docker image: docker run -v ~/src:/src -p 5000:5000 -it microsoft/aspnet. Note that this command mounts the local web app in the Docker container's /src folder.
  • As shown above, run dnu restore and dnx . kestrel to restore dependencies and start the web server.
  • Use the Azure portal to map your cloud VM's port 5000 to the public port 80. With that, you can try your ASP.NET 5 web app running on Linux in a Docker container over the internet (don't forget to change the following adress according to your machine name):

Did it work?

Did you like my session? Did you successfully replayed my demo using the code in this article? I would love to hear your feedback.