Here, I am going to explain how to run an ASP.NET Core application with the help of Docker.

Prerequisites

I have accomplished this task with the help of this software.

Create ASP.NET CORE application

Open VS2017, then go to File->New->Project->Select ASP.NET Core web application and click on OK button, as shown in the below image.

ASP.NET Core

As soon as you select OK button, it will display the below screen. Select Empty Template and check the Enable Docker support checkbox as well as select OS as Windows and click on the OK button, as shown in the below image.

ASP.NET Core

As soon as we click on the ok button we will get to see some Dockerfile, Program.cs, and Starup.cs files under Solution Explorer. All of these files get added automatically.

ASP.NET Core

So far we have created the application with the help of VS 2017. Now we can see the actual beauty of Docker. Generally, after creating an application in Visual Studio, the next step is to build the app and run it.

Docker is not like that. If you observe in solution explorer, we have Dockerfile where things will happen.

Let’s look into the contents of Dockerfile.

ASP.NET Core

First Line FROM Microsoft/aspnetcore:2.0 is the base image for this application in order to run the dot net core application.

ARG source is the argument which helps to pass data to the image.

WORKDIR /app is the working directory of the image; it will store all DLLs inside the app folder.

COPY will copy the DLLs of the application to the root directory (here dot represents root) of the image.

ENTRYPOINT is responsible to run the main application with the help of ASPNETCOREAPP.dll.

Before running the application we have to build and call the publish command.

Open the command prompt & go to project folder where you have created the project. In my case path is c:/users/projects/ASPNETCOREAPP/

Once you are in the specified path execute the below command:

dotnet publish --configuration Release --output ./obj/Docker/publish

Once you are done, you can observe inside obj/Docker folder, the publish folder gets created. This publish folder has all DLLs of your project.

Now once again go to command prompt and try to build an image for your application with the help of Docker.