简体   繁体   中英

Attach to running process inside docker from VS2017

Is there an easy way to debug a process running inside a Linux container on a remote host from Visual Studio?

Imagine a scenario where we have multiple services deployed on some remote machine, running inside docker containers - dev environment. During testing we detect that the internal state of one of the services becomes currupt and need to figure out what's going on in there. We do not want to docker-compose up locally because we might not be able to simulate the scenario.

Instead we want to attach to the running process inside the container.

I read several articles about how to do this, but they are either about Windows containers ( https://www.richard-banks.org/2017/02/debug-net-in-windows-container.html ) or are just plain confusing (eg do I need to install sshd to connect to it from VS? Do I need to install vsdbg as outlined here https://github.com/Microsoft/generator-docker/issues/130 ?)

I tried installing the vsdbg into the container along with ssh, but Visual Studio is not able to find any Remote Connections (in Debug -> Attach to Process).

Is there any tutorial specificly for VS2017 & remote debugging & Docker Linux containers ?

You can try to debug with gdb and ssh like it is showed on this page: https://docs.microsoft.com/en-us/cpp/linux/connect-to-your-remote-linux-computer but this will treat the process as native/unmanaged process. It is basically for debugging C++ applications.

For remote debugging managed processes C#, VB, F# and so on, you can use "remote debugging tools for VS" but they are only for Windows. So for know you can not remote debug C# application on Linux container. Hope this clarifies the things.

To expose those you would have to install the remote debugging tools. Generally there is a different version for each visual studio when using windows, but this should work from 2017 and later editions of visual studio.

https://docs.microsoft.com/en-us/visualstudio/debugger/remote-debugging-dotnet-core-linux-with-ssh?view=vs-2019

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM