How to: Debug Windows containers in Azure Service Fabric using Visual Studio 2019

With Visual Studio 2019, you can debug .NET applications in containers as Service Fabric services. This article shows you how to configure your environment and then debug a .NET application in a container running in a local Service Fabric cluster.


Configure your developer environment to debug containers

  1. Make sure the Docker for Window service is running before proceeding with the next step.

  2. To support DNS resolution between containers, you'll have to set up your local development cluster, using the machine name. These steps are also necessary if you want to address services through the reverse proxy.

    1. Open PowerShell as administrator

    2. Navigate to the SDK Cluster setup folder, typically C:\Program Files\Microsoft SDKs\Service Fabric\ClusterSetup.

    3. Run the script DevClusterSetup.ps1

        C:\Program Files\Microsoft SDKs\Service Fabric\ClusterSetup\DevClusterSetup.ps1


      You can use the -CreateOneNodeCluster to setup a one-node cluster. The default will create a local five-node cluster.

      To learn more about the DNS Service in Service Fabric, see DNS Service in Azure Service Fabric. To learn more about using Service Fabric reverse proxy from services running in a container, see Reverse proxy special handling for services running in containers.

Known limitations when debugging containers in Service Fabric

Below is a list of known limitations with debugging containers in Service Fabric and possible resolutions:

  • Using localhost for ClusterFQDNorIP won't support DNS resolution in containers.
    • Resolution: Set up the local cluster using machine name (see above)
  • Running Windows10 in a Virtual Machine won't get DNS reply back to the container.
  • Resolving services in same application using DNS service name doesn't work on Windows10, if the application was deployed using Docker Compose
  • If using IP-address for ClusterFQDNorIP, changing primary IP on the host will break DNS functionality.
    • Resolution: Recreate the cluster using the new primary IP on the host or use machine name. This breakage is by design.
  • If the FQDN the cluster was created with isn't resolvable on the network, DNS will fail.
    • Resolution: Recreate the local cluster using the primary IP of the host. This failure is by design.
  • When debugging a container, docker logs will only be available in the Visual Studio output window, not through Service Fabric APIs, including Service Fabric Explorer

Debug a .NET application running in docker containers on Service Fabric

  1. Run Visual Studio as an administrator.

  2. Open an existing .NET application or create a new one.

  3. Right-click the project and select Add -> Container Orchestrator Support -> Service Fabric

  4. Press F5 to start debugging the application.

    Visual Studio supports console and ASP.NET project types for .NET and .NET Core.

Next steps

To learn more about the capabilities of Service Fabric and containers, see Service Fabric containers overview.