Question
How do I programmatically attach to a .NET Core process running inside a Docker container on my local machine?
Specifically, I have an integration test which runs a set of Docker containers. I want to attach a debugger to a process inside one of those containers. I know the container, and the process, so all I am looking for is a mechanism to actually attach the debugger programmatically so that when I debug my integration test, I can debug straight into my application.
Background
In Visual Studio 2019 it is possible to attach a debugger to a process running inside a Docker container.
When you start your container mount an additional volume containing vsdbg
(for example, %USERPROFILE%\vsdbg\vs2017u5
) as /remote_debugger
.
docker run -v "$($env:USERPROFILE)\vsdbg\vs2017u5:/remote_debugger:rw"
You can then attach a debugger using Debug -> Attach to Process...
:
Possible options
I suspect that I can do it using EnvDTE (as per this answer) but I was hoping for a simpler mechanism if there is one, as EnvDTE-based solutions are often a maintenance headache.