Docker with coreclr

Docker with coreclr

Overview

I’ve been playing around with my ASP.NET Core microservices on Linux. In the meantime I have build my front-end build pipeline and tried to understand Xamarin Visual Studio Templates. I decided to move to Docker on Ubuntu as I wasn’t able to do it on Windows. However my app on ASP.NET Core on Docker on Ubuntu doesn’t start. Real question is why?!?

Simple Answer

Because google lies. Not intentionally but most of the documentation around ASP.NET Core is outdated. Following guideline and very cool blogpost doesn’t help much.

Docker with coreclr

One of many, but current issue is that my image is already built.

mogluszka@mogluszkaW540:~/Sources/shout/src/userService$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
userservice         latest              31dc7719a8e4        16 minutes ago      1.337 GB

However when I try to run it according to documentation, I get nothing.

mogluszka@mogluszkaW540:~/Sources/shout/src/userService$ docker run -t -d userservice
4fce232e7a0644296de8c4cfd4929d0788f48acf24c4291ef46f0e219d83447f
mogluszka@mogluszkaW540:~/Sources/shout/src/userService$ 

Process terminates itself just after being run. Doing simple test show reason behind this error.

mogluszka@mogluszkaW540:~/Sources/shout/src/userService$ docker run -t userservice
System.InvalidOperationException: The current runtime target framework is not compatible with 'userservice'.
Current runtime target framework: 'DNX,Version=v4.5.1 (dnx451)'
 Version:      1.0.0-rc1-16231
 Type:         Mono
 Architecture: x64
 OS Name:      Linux
 OS Version:   debian 7
 Runtime Id:   ubuntu.14.04-x64

Please make sure the runtime matches a framework specified in project.json
  at Microsoft.Dnx.ApplicationHost.DefaultHost.GetEntryPoint (System.String applicationName) [0x00000] in :0 
  at Microsoft.Dnx.ApplicationHost.Program.ExecuteMain (Microsoft.Dnx.ApplicationHost.DefaultHost host, System.String applicationName, System.String[] args) [0x00000] in :0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in :0 
  at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute (System.Reflection.Assembly assembly, System.String[] args, IServiceProvider serviceProvider) [0x00000] in :0 
  at Microsoft.Dnx.Host.Bootstrapper.RunAsync (System.Collections.Generic.List`1 args, IRuntimeEnvironment env, System.String appBase, System.Runtime.Versioning.FrameworkName targetFramework) [0x00000] in :0 

This is shown because The -d switch runs the container in the background, otherwise the web server’s standard input/output streams would be attached to our development machine’s shell. So I have removed it.
As I have seen this already in dnxcore50 vs dnx451, I know that real case is that my project enfroces usage of dnxcore50, so coreclr. On docker it’s running on wrong target framework.

  "frameworks": {
    "dnxcore50": { 
        "dependencies": {
        }
     } 

And I have done it by purpose, I don’t want to use mono and now I want to have docker with coreclr.
Solution is to modify Dockerfile to use proper image and up to date kestrel command.

FROM microsoft/aspnet:1.0.0-rc1-update1-coreclr

COPY . /userservice
WORKDIR /userservice

RUN ["dnu", "restore"]

EXPOSE 5000
ENTRYPOINT ["dnx", "kestrel"]

Now we will get result as expected:

mogluszka@mogluszkaW540:~/Sources/shout/src/userService$ docker run -t userservice
Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

One thought on “Docker with coreclr

Leave a Reply

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