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.
- On Windows 10, follow this quickstart to Configure Windows 10 to run Windows containers
- On Windows Server 2016, follow this quickstart to Configure Windows 2016 to run Windows containers
- Set up your local Service Fabric environment by following Prepare your development environment on Windows
Configure your developer environment to debug containers
Make sure the Docker for Window service is running before proceeding with the next step.
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.
Open PowerShell as administrator
Navigate to the SDK Cluster setup folder, typically
C:\Program Files\Microsoft SDKs\Service Fabric\ClusterSetup.
Run the script
C:\Program Files\Microsoft SDKs\Service Fabric\ClusterSetup\DevClusterSetup.ps1
You can use the
-CreateOneNodeClusterto 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.
- Resolution: Disable UDP checksum offload for IPv4 on the Virtual Machines NIC
- Running Windows10 will degrade networking performance on the machine.
- Resolving services in same application using DNS service name doesn't work on Windows10, if the application was deployed using Docker Compose
- Resolution: Use servicename.applicationname to resolve service endpoints
- 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
Run Visual Studio as an administrator.
Open an existing .NET application or create a new one.
Right-click the project and select Add -> Container Orchestrator Support -> Service Fabric
Press F5 to start debugging the application.
Visual Studio supports console and ASP.NET project types for .NET and .NET Core.
To learn more about the capabilities of Service Fabric and containers, see Service Fabric containers overview](service-fabric-containers-overview.md).