Jun 15, 2016

Running .NET Core in Docker container

I was following news about both Docker and .NET Core for quite a while, so decided to try to combine them in single experiment. I’ll describe there my experience doing that, mainly the information for my attempt has been taken from this Channel9 video.
The idea: run the .NET Core simple application (hello world) in a Linux container provisioned by Docker ecosystem.



The prerequisites: docker engine installed. I’ve already had Docker Toolbox installed from my previous experiments, the version, however, was a little bit obsolete. So I downloaded new one, installed and tried docker CLI tools to find what is running. Nothing was.
I have had a VirtualBox's VM for hosting containers, but it was in a “Saved” state and unwilling to change it. Even removal from command line didn’t work, so I removed it through VirtualBox’s interface. Then I tried to create a new one with CLI, it failed and after short googling I found the answer in the Hanselman’s post. I switched to the newly created boot configuration and voila, up and running (here and below I use Powershell):
1 create docker host vm
It is not enough to be able to connect to that machine, “docker” commands were not able to do anything:
2 docker need network
The truth is, the docker machine needs to be configured – the “docker-machine env default” command gives what you need to run to be able to connect. This configuration would have to be done for each terminal session:
3 configure docker machine
I tried to run one small container (BusyBox) and that succeeded:
4 try busybox
The app – I needed something to run, so I created it:
5 create net core app
Then I needed the binaries, dotnet publish will do the job. Here I am doing publishing into ‘app’ folder:
6 restore build and publish
The next step – create a container from binaries.
docker needs a config file for the container composition, here is mine (should be named “dockerfile” in project root folder):
FROM microsoft/dotnet:1.0.0-rc2-core
WORKDIR /app
COPY /app /app
ENTRYPOINT dotnet dockerhello.dll
3 commands, and your container is ready:
7 create docker container
But not running. It appeared to be a error in config file – the casing for the files matters, here is the corrected line:
ENTRYPOINT dotnet dockerHello.dll
Short fix and here it is:
8 finally done
I also wanted to try https://beta.docker.com/ and run without VirtualBox – using Hyper-V, but that’s probably for the next time.

2 comments:

Mary Petter said...
This comment has been removed by a blog administrator.
Escort Couple West Bromwich said...

Thank you for beinng you