다음을 통해 공유


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.

image

Step 2: Select Web Application template. DO NOT  check “Enable Docker Support”

image

Step 3: Once the application is loaded in Visual Studio add a Dockerfile to the root of the project.

image

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 https://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.

image

Step 7. Exexute Docker run command to create the container using the image previously created as shown below

image

Step 8. Inspect the IP address on which the container is running by executing network inspector nat command.

SNAGHTML318dca

Step 9. Open the web browser and navigate to the IP address and you will see the ASP.Net core application running.

image

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

image

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.

image

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.

image

Step 13. Once the application is created and loaded, add the following endpoint information into ServiceManifest.xml

image

Step 14. Now let’s add following section into ApplicationManifest.xml to add Hub Credentials and Port Binding endpoint information.

SNAGHTML4f39dc

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.

image

Step 16. First let’s see our application deployed using Service Fabric explorer.

image

Step 17. Now, lets browse to our application on Service Fabric.

image

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!

Comments

  • Anonymous
    July 28, 2017
    Why it is so complicated? We need to do 2 independent operations. Why we can't add Stateless ASP.NET Core (Service Fabric Service) in Visual Studio 2017 and ask it to publish into Service Fabric Cluster not "as is" but wrapped into a Docker Container?And why is it so necessary to publish container from a registry? How about local container images that we didn't push to registry yet?
    • Anonymous
      August 10, 2017
      Thanks for the feedback Yuri. The integration you are mentioning about makes total sense and is part of the backlog. With respect to need for registry, that's because containers cannot be run in local SF cluster on Win 10 today..but be rest assured is part of backlog and/or being worked upon. Hope that helps!
  • Anonymous
    September 14, 2017
    I found this tutorial after a whole week of trying to publish my locally working project in my ServiceFabric Cluster. Independent from what I do it sais: 'Page not reachable'. Now I even have the same problem following your tutorial above. So the project is not the problem as it seems!?So hat could be wrong then? Which internet address do you use to connect to the cluster in the very last step?