Menu

Sitecore: Docker Debugging with Visual Studio

sitecore icon

Sitecore: Docker Debugging with Visual Studio


July 30th, 2020

Since update 16.5 of Visual Studio 2019, debugging processes inside of a Windows container is natively supported. More details in the release notes.

Previously, a common method of debugging inside the container was to mount the remote debugger folder found in the Visual Studio directory on the host as a docker volume and then run the remote debugger in the image entry point.

I found on my team that this could get problematic when team members were using different versions of Visual Studio. For example, the VS install for user running Visual Studio Enterprise, Professional and Community are all different. As is the paths for preview versions of VS.

None of this is required anymore. You can remove any volume mounts for the remote debugger from your docker-compose.yml files.

Instead, remote debugging happens natively in Visual Studio 2019 16.5+ and all you need to do is follow these simple steps to start debugging your containerized sites:

  1. Select Debug > Attach to process or hit Ctrl+Alt+P.
  2. In the Connection Type dropdown, select "Docker (Windows Container)"
  3. Next to the Connection Target field, hit the "Find" button. In the dropdown that opens, select your container (i.e. mysite_cm_1).
  4. Next to the Attach To field, select the Select button.

    • In the dialog that opens, check the Debug these code types: radio and then check the Managed (v4.6, v4.5, v4.0) checkbox.
    • [Optional] You can also check the Native option.
    • Press ok.
  5. Select "w3p.exe" to being debugging.

    • If you don't see this process, first make sure that the site has been spin up (browse to accelerator.dev.local in your browser) and make sure that "Show processes from all users" is checked.

Alternatively, if you have the VS Container Tools Extension installed, you can also attach your debugger using that.

If the "Containers" window is not open, you can go to View > Other Windows and select "Containers" to open it.

From within the "Containers" window, find your container you want to attach to (i.e. "mysitecm1"), right-click and then select Attach to process. In the dialog box that opens, select "w3p.exe". If you don't see it, make sure "Show processes from all users" is checked. Then hit Attach.

(Optional) DNS Configuration

My team ran across some DNS issues inside the containers. For some reason, they were unable to resolve Microsoft's domain when downloading the VS remote debugger. We resolved this by adding the following DNS configuration to our docker-compose.yml

cm:
  # ...
  dns:
  - 1.1.1.1
  - 8.8.8.8

This tells the CM service to use Cloudflare's DNS server -- with Google's as a backup -- for DNS resolution. This step may not be necessary for you. By default, the container should try to use whatever DNS settings the host machine has set.

That's it. You can debug like you would with a typical, non-containerized local site.

Happy bug hunting!

© 2023 Stefan Perales

Built with by peralysis