Debug code running in XC containers

Abstract

This topic shows how to debug Commerce Engine code that is running in a container.

This topic explains how to use Visual Studio to view and diagnose your Commerce Engine code when it is running in a local Docker container. It assumes that you know how to build and run custom Docker runtime images that include the build output for your Commerce solution.

To debug apps in a local Docker container, you must use Visual Studio 2019 version 16.5.0 or later.

Note

Though not unique to containers, you must ensure that debug symbols have been deployed to the container. This might already be done if you are building your solution image with the Debug build configuration.

You can also do a Debug file deployment from Visual Studio into the running container.

In Visual Studio, you have two options for attaching the debugger to a process in a container:

To attach the Visual Studio debugger to a process running in a container:

  1. If the Containers window is not showing, open it from the top View menu. Click Other Windows, then Containers.

  2. In the list of running containers, right-click the one that you want to debug, for example container_engine_authoring_1, and click Attach to Process:

    In Visual Studio, the Attach to Process option in the dialog box containing debugging actions.

    The Attach to Process dialog opens.

  3. In the Attach to Process dialog, to debug a Commerce Engine dotnet.exe process, use code type Automatic: Managed(.NET Core, .NET 5+)code, as shown in the following example:

    The Attach to Process dialog box with the dotnet.exe process selected.
  4. Click Attach.

Alternatively, you can use the Visual Studio Debug menu.

To attach the Visual Studio debugger to a process running in a container:

  1. In Visual Studio, in menu bar, click Debug, and then click Attach to Process. The Attach to Process dialog box opens.

  2. In the Connection type, drop-down list, click Docker (Windows Container).

  3. In the Connection target field, click Find. Running containers appear in the list. Click the container you want to debug, and click OK.

  4. In the Attach to field, select the correct type. To debug a Commerce Engine dotnet.exe process, use code type Automatic: Managed(.NET Core, .NET 5+)code.

  5. Click Attach.