Docker Blog Series Part 2 - Build & Deploy ASP.NET Core based Docker Container on Service Fabric
Azure Service Fabric in addition to offering a Service Fabric programming model is also able to orchestrate container based services across a cluster of machines. Service Fabric can deploy services in container images. In this blog post, we will see how to use Service Fabric as an orchestrator for Windows based Docker images. The images will be published to Docker Hub and consumed by the Service Fabric orchestrator. We will build an ASPNET Core Web application, Dockerize it and publish it to Docker Hub. Finally we will publish the image to a Service Fabric Cluster.
Step 1: Create a ASPNET Core Web Application using Visual Studio.
Step 2: Select Web Application template. DO NOT check “Enable Docker Support”
Step 3: Once the application is loaded in Visual Studio add a Dockerfile to the root of the project.
Step 4. Open the Dockerfile in Visual Studio and add the following steps in the Dockerfile and Save the Dockerfile.
|FROM microsoft/dotnet:1.1-sdk-nanoserverENTRYPOINT ["dotnet", "bin/Debug/netcoreapp1.1/DemoCoreApp.dll"]WORKDIR dockerdemoADD ./DemoCoreApp .RUN dotnet restore DemoCoreApp.csprojRUN dotnet build DemoCoreApp.csprojEXPOSE 80ENV ASPNETCORE_URLS http://0.0.0.0:80|
Step 5. Open Powershell in Admin Mode and browse to the project folder.
Step 6. Execute Docker build command to build image from the Dockerfile. Include tag name in the build command as shown below.
Step 7. Exexute Docker run command to create the container using the image previously created as shown below
Step 8. Inspect the IP address on which the container is running by executing network inspector nat command.
Step 9. Open the web browser and navigate to the IP address and you will see the ASP.Net core application running.
Step 10. Publish the image to Docker Hub so that it can be consumed from Service Fabric. Before pushing login to Docker Hub using login command
Now we will use the image from Docker Hub to deploy to a Service Fabric Cluster.
Let’s begin building the Service Fabric Orchestration piece.
Step 11. Open Visual Studio 2017 and create a Service Fabric Application.
Step 12. Now choose the Guest Container feature and provide valid Image Name and Click Ok. The image name is the one we published to Docker Hub in the previous exercise.
Step 13. Once the application is created and loaded, add the following endpoint information into ServiceManifest.xml
Step 14. Now let’s add following section into ApplicationManifest.xml to add Hub Credentials and Port Binding endpoint information.
Step 15. We are ready to Publish our application to Service Fabric Cluster now. Right click on the Application and Publish to Azure Service Fabric. Make sure when you create the Service Fabric cluster, you pick the option to create it with Windows Server 2016 with Containers.
Step 16. First let’s see our application deployed using Service Fabric explorer.
Step 17. Now, lets browse to our application on Service Fabric.
As you saw in this blog post we can use Service Fabric for Container Orchestration. More coming in next blog on Container Orchestration capabilities like DNS, Scaling, Labels etc.. Stay tuned!