.NET Developer Conference 2017

My presentation and samples from conference.

Samples: https://github.com/ddobric/samples/tree/master/netcore20
Presentation:https://www.slideshare.net/damirdobric/net-core-822595

Here is a short part from github samples:

How to run .NET Core application in docker container?

First, we have to publish the application for OS of the base image. Here is an example for debian auf x64 platform:

dotnet publish -r debian-x64 -f netcoreapp2.0

Then create the file with the name dockerfile and paste following code in the file:

FROM microsoft/dotnet
ARG EXE_DIR=. 
WORKDIR /app 
COPY $EXE_DIR/ ./ 
CMD ["./mydocsample"] 

This defines the new image on top of the microsoft/dotnet base image. I have used microsoft/dotnet as base, but it is not required to have dotnet installed on the image, because our publish has published required framework assemblies for runtime *debian-x64 *.

As next the docker image has to be built:

docker build --build-arg EXE_DIR=./bin/Debug/netcoreapp2.0/debian-x64/publish -t ddc:3.0.

This will create the new images with name ddc and version (tag) 3.0. If you execute now
docker images
you will see following:

REPOSITORY                                                                      TAG                              IMAGE ID            CREATED             SIZE
ddc                                                                             1.2                              8d8e7c5186c6        43 hours ago        1.75GB
ddc <--                                                                         3.0 ,<--                         8d8e7c5186c6        43 hours ago        1.75GB
fra                                                                             1.0                              8d8e7c5186c6        43 hours ago        1.75GB
ddc                                                                             1.0                              6779ba25cd4d        45 hours ago        284MB
microsoft/dotnet                                                                latest                           84b39efffa19        8 days ago          1.68GB

Note the second entry in the list. It new is the image, which has been created.

To run the container with .NET Core application execute following command:
docker run 8d8e7c5186c6

To run it in the backgraound:
docker run 8d8e7c5186c6

C:\mydocsample>docker run 8d8e7c5186c6
Hello World!
Hello World!
Hello World!
Hello World!

To see running container:
docker ps

you will see the container is running:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
a0f200ad8fb4        8d8e7c5186c6        "./mydocsample"     45 seconds ago      Up 44 seconds                           adoring_kalam

comments powered by Disqus