Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (e.g. 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 ?

like image 495
Tomáš Bezouška Avatar asked Sep 11 '17 15:09

Tomáš Bezouška


People also ask

How can I run another process inside a running container?

Use a process manager which can run multiple processes: You can set the container's entrypoint to a specialised program which is capable of running and managing multiple processes. One example of this is supervisord. You can use supervisord as your container entrypoint, which will then load the services that you need.

How do you attach a terminal to a running Docker container?

Use docker attach to attach your terminal's standard input, output, and error (or any combination of the three) to a running container using the container's ID or name. This allows you to view its ongoing output or to control it interactively, as though the commands were running directly in your terminal.

Can you interact with an application inside a container?

The answer is yes!! But using normal docker run commands, you won't be able to see or interact with the these applications. You need to connect the display with the container in order to do so.


1 Answers

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.

like image 157
Ivelin Ivanov Avatar answered Oct 12 '22 11:10

Ivelin Ivanov