Creating an ASP.NET Core web application

Following are the simple steps to get started:

  1. Create a new project by navigating to File | New Project | .NET Core | select ASP.NET Core Web Application, refer to the following screenshot:
  1. From the New ASP.NET Core Web Application window, select .NET Core and ASP.NET Core 2.0.
  2. Select Web Application (Model-View-Controller) from available templates.
  3. Check Enable Docker support.
  4. As we are demonstrating it for Windows select OS as Windows (if you did not install Docker as mentioned in the previous section, here you need to install Docker for Windows).
  5. Click Ok to proceed, refer to the following screenshot:

The preceding steps will create the FlixOne.BookStore.ProductService project with Docker support. Following is the screenshot showing our project structure:

The following files are added to the project:

FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "FlixOne.BookStore.ProductService.dll"]

The preceding code is basically a set of instructions and these instructions are as follows:

FROM tells Docker that to pull the base image on the existing image, call microsoft/aspnetcore:2.0. This image already contains all the dependencies for running the ASP.NET Core on Linux, so we don't have to set it.

COPY and WORKDIR copy the current directory's contents to a new directory inside the called/app container and set it to the working directory for subsequent instructions.

EXPOSE tells Docker to expose the product catalog service on port 80 of the container.

ENTRYPOINT specifies the command to execute when the container starts up. In this case, it's .NET.

The docker-compose.yml file contains the name of the image that is created when the project is run.

We now have everything we need to run/launch our service in the Docker container. Before we go further, please refer to Chapter 2, Implementing Microservices, and add the complete code (that is, controller, repositories, and so on) so the project structure looks like the following screenshot:

Now all you have to do is press F5 and launch your service in the container. This is the simplest and easiest way to put your service in the container. Once your microservice is containerized, you can use Visual Studio team services and Azure container services to deploy your container to the Azure cloud (https://docs.microsoft.com/en-us/azure/container-service/dcos-swarm/container-service-deployment).