Docker on Windows – ASP.NET Core

docker

What is Docker?

Docker is a tool for running processes in an isolated environment called a container. It’s like a virtual machine but it doesn’t need opereting system. No matter if we run our application on linux, macOS or windows everywhere will be work the same. In contrast to „normal publish” where – we move our release versions between different systems or even different versions of the same system that might not work for us.

There is the graphic difference between VM and Docker. Pay attention to how much the resource consumes „Guest OS (System operations)” in VM.

virtualization-vs-containers
http://crmtrilogix.com/Cloud-Blog/AWS/Docker-Containers-VMs-and-ECS—an-overview/219

For more information what is docker I refer to the link.

How to configure Docker in Windows.

Now let’s see how we can configure Docker in windows.
First we need to install docker (here is tutorial for Windows, MacOS and Linux).

We need a some project. In my example will be a Asp.Net Core MVC.

Let’s use SDK which offers us microsoft and create a project from the console. Go to your folder and write dotnet new mvc that will create example project based on MVC. There is alot of option that SDK offerds – just write the dotnet –help in console to see them. But I won’t write about it in today’s post.

dotnet new mvc

After use dotnet run we should get a example page.

mvc core

Ok. Now let’s create a Dockerfile without any extension, it will define the imaging configurations based on this project.

dockerfile
*I’m using Visual Studio Code

 

FROM – It informs that we will use an image called microsoft/dotnet which is sufficient to launch the Asp.Net Core.

COPY/WORKDIRIt copies the current contents of the directory to a new one called app and sets this directory as the default for subsequent instructions.

EXPOSEto expose on port 5000 outside the world.

ENV ASPNETCORE_URLSIt binds the port and address of our application.

ENV ASPNETCORE_ENVIRONMENT development – here we can set whether our application is development  production etc.
ENTRYPOINTSpecifies the command that will be executed when the container is started.
We can also add commands eg. RUN [„dotnet”, „restore”], RUN [„dotnet”, „build”] – to restore and build our aplication.

Now we can create image docker.

The -t parametr adds a tag to our image in our example it’s „someapp”. The „.” on the end says that we want to use the dockerfile in the current directory.

We can check our images with:

After build we can try run our application localy with docker.

The -d parametr allows you to run an application in detached mode that means it will run in the background and parametr -p sets port mapping. Now our application should work on http://localhost:5000/.

To see the currently active images, you should write a command:

docker

Now we can put our image into the cloud like digital oceandocker hub and so on.

 

But what if we’ve got many services like database, rabitMq and etc?For each instance I have to make a separate image?

So that’s where a Docker Compose in. But about docker compose I will write in subsequent posts.

4 Comments on “Docker on Windows – ASP.NET Core”

      1. No bo końcówka .pl 😀 Miałem dysonans poznawczy! Zrób ankiete: „Jaki jest Twój natywny język?” i zobaczysz że 80% będzie polski (a pozostałe 20% pewnie napisze: java, .net, c++… :P).

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *