简体   繁体   English

从 VS2017 附加到 docker 中正在运行的进程

[英]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?是否有一种简单的方法可以从 Visual Studio 调试远程主机上的 Linux 容器内运行的进程?

Imagine a scenario where we have multiple services deployed on some remote machine, running inside docker containers - dev environment.想象一个场景,我们在某个远程机器上部署了多个服务,在 docker 容器 - 开发环境中运行。 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.我们不想在本地进行docker-compose up ,因为我们可能无法模拟场景。

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 ?)我阅读了几篇关于如何做到这一点的文章,但它们要么是关于 Windows 容器的( https://www.richard-banks.org/2017/02/debug-net-in-windows-container.html ),要么只是简单的令人困惑(例如,我是否需要安装 sshd 才能从 VS 连接到它?我是否需要按照https://github.com/Microsoft/generator-docker/issues/130 中的概述安装 vsdbg ?)

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).我尝试将 vsdbg 与 ssh 一起安装到容器中,但 Visual Studio 无法找到任何远程连接(在调试 -> 附加到进程中)。

Is there any tutorial specificly for VS2017 & remote debugging & Docker Linux containers ?是否有专门针对 VS2017 & 远程调试 & Docker Linux 容器的教程?

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.您可以尝试使用 gdb 和 ssh 进行调试,如本页所示: https : //docs.microsoft.com/en-us/cpp/linux/connect-to-your-remote-linux-computer但这会处理作为本机/非托管进程的进程。 It is basically for debugging C++ applications.它主要用于调试 C++ 应用程序。

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.对于远程调试托管进程 C#、VB、F# 等,您可以使用“VS 远程调试工具”,但它们仅适用于 Windows。 So for know you can not remote debug C# application on Linux container.所以知道你不能在 Linux 容器上远程调试 C# 应用程序。 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.通常,在使用 Windows 时,每个 Visual Studio 都有不同的版本,但这应该适用于 2017 及更高版本的 Visual Studio。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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