Insights

How to Attach To Process When Using Docker Containers in Sitecore

A look at how attach to process when using .NET based solutions inside of a container.

Attachment Issues

This directly impacts us in the Sitecore world when developing for XM Cloud or using containers, but these same steps apply to anyone who needs to attach to (a) process inside of container from Visual Studio for debugging.

How To Debug Using Attach To Process Inside A Container

In the case of Sitecore XM Cloud dev environments the Content Management server is running on IIS inside of a container. Let’s take a look at the few simple steps.

A look at how attach to process when using .NET based solutions inside of a container.

Find the following path through the menu View > Other Windows > Containers.

A look at how attach to process when using .NET based solutions inside of a container.

In the Containers window right-click on the container of your choice. In our case, we’re going to right-click the container ending in dev_cm_1, then select Attach to Process.

A look at how attach to process when using .NET based solutions inside of a container.

To ensure we’re finding the right process in the correct mode, ensure Show processes for all users is checked, that we’re attaching to Managed (.NET) code and finding the w3wp.exe process.

A look at how attach to process when using .NET based solutions inside of a container.

Double-check that we have the latest code building in debug mode deployed to your container, you should be able to hit your breakpoint.

Please note, you can right-click on your project in the Solutions Explorer window and select Publish to push your updated C# code into your container for testing without doing an entire compose down and up.

In Closing

This example was done on Visual Studio 2022 using Windows Server. I did not encounter any errors or have to do any additional configuration but one person I shared this with did encounter a sort of certificate or trust error when trying to attach to process. Windows, don’t ever change.

Happy debugging and thanks for reading.



Meet Dan Cruickshank

President | Sitecore MVP x 11

Dan is the founder of Fishtank. He's a multi-time Sitecore MVP and Coveo MVP award winner. Outside of technology, he is widely considered to be a top 3 father (routinely receiving "Father of the Year" accolades from his family) and past his prime on the basketball court.

Connect with Dan