Learn how to create your first ASP.NET Core 2.0 Service Fabric Container application in Windows.
So, it all started when I wanted to host a very basic ASP.NET Core API app on Azure. I had many options, like hosting it as an App Service or hosting inside service fabric, and hosting inside the service fabric using containers. The third option is something I wanted to explore more as I had almost no knowledge on this topic except what an image and what a container means.
Note All the steps that are described here are true as per today's releases. If things are updated later, I'll try to update this post too :) Prerequisites
A development computer running,
Not going into details; you can find many articles to start with ASP.NET Core 2.0. But at the end, it is a basic API app. Below is the solution structure.
Typical asp.net core 2.0 solution structure
The controller has a basic get method to get the top and random quotes/lines, nothing special. I copied it from this blog post. Create a Docker image (locally)
Here comes the interesting part when you need to create a Docker image (based on Windows). So, let's first create a docker file inside the solution. Add a new file called DockerFile in the project and add the below lines.
There are many ways to build an ASP.NET Core API app and build an image, e.g. you can build in your own machine & then containerize it from the published location. Or you can actually build and publish it inside a container & then create an image out of it. I'm taking the 2nd route here.
Let's explore whats the 'BUILD PHASE' in the docker file. Let me write the 6 lines under the build phase in plain English.
Hope this makes sense now :)
So same for 'RUN PHASE'.
A few things to notice...
Once done, you can execute the docker images command from PowerShell to check that the image is created.
Now, you have the image on your local machine. So you need to publish it to some place from where Azure Service Fabric can download or rather anyone else can download and use your app. You can either publish it to public docker hub repository or publish it to Azure Container repository.
Once uploaded, you now have the image on the Docker Hub. We can use this image to deploy our Service Fabric service. Let's do that now. Create the containerized service in Visual Studio
The Service Fabric SDK and tools provide a service template to help you create a containerized application.
In 'ServiceManifest.xml' file expose expose 8080 as the public port for the api app you are going to publish. <Endpoint Name="QuotesServiceTypeEndpoint" UriScheme="http" Port="8080" Protocol="http" />
Now, you can monitor your service fabric explorer to check the health status of the app you deployed. It will be in error state for some moment until SF downloads the image from the Docker Hub & installs in the node & starts the same.
Let me know if you face any issues. Also, you can find more details on MSDN.
Pro WPF: Windows Presentation Foundation in .NET 3.0