ASP.NET 5.0 and Docker on Windows – Part I

docker

Overview

I’m using various systems on daily basis: Ubuntu, Windows 10, Windows 8. As world has changed for Microsoft and they love Linux now, let’s see can we do parallel development on Linux and Windows. Unfortunately I don’t have development environment on my Windows machines. And I have no idea about docker as well. I like learning by doing, so…

.NET Core 1.0

It seems that there is no released ASP.NET Core 1.0 (renamed from ASP.NET 5.0 ASP.NET 5.0 is Dead). In previous post we have written simple Hello World on Ubuntu with .NET Core 1.0. This surprisingly compiles on Windows machine as well.

.netWindows

A bit of ASP.NET 5 code

https://docs.asp.net/en/latest/tutorials/first-mvc-app/index.html

But as usual I have just created Empty Web App in Visual Studio with .NET Framework 4.6 in ASP.NET 5.0. Seems to work fine, interesting is that it’s using 1.0 RC as a reference.

“dependencies”: {
“Microsoft.AspNet.Server.IIS”: “1.0.0-beta5”,
“Microsoft.AspNet.Server.WebListener”: “1.0.0-beta5”
},

Explaining ASP5.0 as a whole would require few posts, so if you are interested http://blog.scottlogic.com/2015/05/14/aspnet50-intro.html.

Source code has been pushed to new branch and let see can we run it on Docker.

https://github.com/michalogluszka/shout/tree/asp5ondocker

What is Docker?


 

Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.

https://www.docker.com/what-docker


 

Main Docker Parts

  1. docker daemon: used to manage docker (LXC) containers on the host it runs
  2. docker CLI: used to command and communicate with the docker daemon
  3. docker image index: a repository (public or private) for docker images

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-getting-started

dockerContainers

 


 

Installing Docker on Windows

https://docs.docker.com/windows/step_one/

Because the Docker Engine daemon uses Linux-specific kernel features, you can’t run Docker Engine natively in Windows. Instead, you must use the Docker Machine command, docker-machine, to create and attach to a small Linux VM on your machine. This VM hosts Docker Engine for you on your Windows system.

Ooooohhh cool, so I assume it won’t work that easy as .NET on Ubuntu 🙂 . Seems that Microsoft loves Linux more then they do. So let’s follow the steps and see can I make it.

And I believe I need to be more trustful… we have another hello world on this blog.

helloWorldDocker

Running .NET Core 1.0 on Docker

I just realized that before jumping into building ASP.NET 5.0 on Docker, it will be more reasonable to test .NET Core 1.0 Hello World app from: https://github.com/michalogluszka/shout/tree/aspnetcore

ASP.NET 5.0 will fail on docker, at least this is my assumption as usual. I told you I’m pessimist.

This seems to work, kind of uprising.

aspcoreondocker

 

 

 

 

 

Running Shout ASP.NET 5.0 on Docker

Let’s test ASP.NET code from https://github.com/michalogluszka/shout/tree/asp5ondocker

aspondocker

It seems to be ridiculous, but I’m happy that it has failed. At least it seems that I understand something. So why this fails? Let’s start digging around.

Docker uses containers and images, which should be helpful. Uncle google replies to my questions with microsoft/aspnet image that should allow me to run my website.

A bit of more digging results in finding interesting blog posts:

  • https://blogs.msdn.microsoft.com/webdev/2015/01/14/running-asp-net-5-applications-in-linux-containers-with-docker/
  • http://dotnetliberty.com/index.php/2015/10/25/asp-net-5-running-in-docker-on-windows/
Step 1 – Running Image
docker run -v ~/Projects/shout/src/shout:/shout -p 5000:5000 -it microsoft/aspnet

This should run aspnet docker image with my source code on port 5000.

Step 2 – Restoring packages
$dnu restore

 

What is DNU? 

DNU is used to manage the packages required by an application to run.   DNU is used to manage the dependencies in a .NET 5 application by installing or restoring the packages associated with a project (see project.json).   This can pull down new versions or repair versions that are not set up correctly. 

http://www.dnnsoftware.com/community-blog/cid/155264/what-are-dnx-dnvm-dnu-and-other-aspnet-5-components


 

This seems to work correctly 🙂

Restore complete, 105655ms elapsed
Feeds used:
 https://api.nuget.org/v3-flatcontainer/
Installed:
 106 package(s) to /root/.dnx/packages
Step 3 – Running app
$dnx web

What is dnx?

DNX contains the components required to run an ASP.NET 5 application.  The ASP.NET Github wiki describes DNX as an SDK containing everything needed to build and run an ASP.NET 5 application.   This includes the compilation and native CLR hosts – everything required to load up a .NET program and execute the instructions inside.

http://www.dnnsoftware.com/community-blog/cid/155264/what-are-dnx-dnvm-dnu-and-other-aspnet-5-components


And it fails…

root@0326300d2dde:/shout# dnx web
System.InvalidOperationException: No service for type ‘Microsoft.Framework.Runtime.IApplicationEnvironment’ has been registered.

Let’s see what I have on docker:

root@0326300d2dde:/shout# mono --version
Mono JIT compiler version 4.0.4 (Stable 4.0.4.1/5ab4c0d Tue Aug 25 23:11:51 UTC
2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-proj
ect.com
 TLS: __thread
 SIGSEGV: altstack
 Notifications: epoll
 Architecture: amd64
 Disabled: none
 Misc: softdebug
 LLVM: supported, not enabled.
 GC: sgen
root@0326300d2dde:/shout# dnvm list

Active Version Runtime Architecture OperatingSystem Alias
------ ------- ------- ------------ --------------- -----
 1.0.0-rc1-update1 mono linux/osx default

Wild guess is saying that maybe there are issues with versions. This is release candidate, but my dependencies in packages.json are for beta5.

This line should start a docker with 1.0.0-beta5 image.

$ docker run -v ~/Projects/shout/src/shout:/shout -p 5000:5000 -it microsoft/aspnet:1.0.0-beta5
$ dnu restore
$ dnx . web (dnx web doesn't work on this image)

root@5b3e93741d90:/shout# dnx . web
System.IO.DirectoryNotFoundException: /shout/wwwroot/

$ mkdir wwwroot

root@5b3e93741d90:/shout# dnx . web
System.TypeInitializationException: An exception was thrown by the type initializer for HttpApi ---> System.DllNotFoundException: httpapi.dll
 at (wrapper managed-to-native) Microsoft.Net.Http.Server.UnsafeNclNativeMethod
s/HttpApi:HttpInitialize (Microsoft.Net.Http.Server.UnsafeNclNativeMethods/HttpA
pi/HTTPAPI_VERSION,uint,void*)


Aaaaarghhh…. I need to go back to KISS development.

Last few tries… Kestrel?

Kestrel

Kestrel seems to be new web server for ASP.NET 5. Looking into my package.json:

"dependencies": {
 "Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
 "Microsoft.AspNet.Server.WebListener": "1.0.0-beta5"
 },
"commands": {
 "web": "Microsoft.AspNet.Hosting --config hosting.ini"
 },

So I’m using IIS by default. Let’s try to use Kestrel instead.

"dependencies": {
 "Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
 "Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
 "Kestrel": "1.0.0-beta5"
 },
"commands": {
 "web": "Microsoft.AspNet.Server.Kestrel",
 "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --config hosting.ini"
 },

Some changes… and repeating steps again

$ dnx . kestrel

Started…

Aaaaaand… black screen. Hmm it’s a progress but no exception. I believe this requires a bit more reasonable approach, not try and see.

Summary

  • it’s tough, mainly there are issues with different beta and RC version for these packages
  • I still don’t see major reason to do it on such early stage of application
  • Linux may be easier to set it up, so this will be a next post

 

One thought on “ASP.NET 5.0 and Docker on Windows – Part I

Leave a Reply

Your email address will not be published. Required fields are marked *