Open Visual Studio, go to New Project and Select ASP.NET Core Web Application as shown below:
Once you click on Ok, you will get the below screen where you have to select the checkbox ‘Enable Docker Support (Requires Docker for Windows)’ and OS as ‘Windows’.
There is also a hyperlink given ‘Requires Docker for Windows’, which can be used to install docker for Windows. In case you didn’t install docker before starting this exercise, it can be done now by clicking on this hyperlink. You can also verify the docker installation by typing the below command on Windows PowerShell:
FROM microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk-nanoserver-1803 AS build
WORKDIR /src
COPY ["ContainerBasedApp/ContainerBasedApp.csproj", "ContainerBasedApp/"]
RUN dotnet restore "ContainerBasedApp/ContainerBasedApp.csproj"
COPY . .
WORKDIR "/src/ContainerBasedApp"
RUN dotnet build "ContainerBasedApp.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "ContainerBasedApp.csproj" -c Release -o /app
FROM base AS final
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ContainerBasedApp.dll"]
docker-compose up
docker-compose down