How to deploy and debug a program from a devcontainer on a remote system?

J. Müller 0 Reputation points
2025-11-06T16:56:13.43+00:00

My desired workflow would be to open my C++ project in VS22 on my Windows system, built the binary in a Linux based devcontainer and deploy it for remote-debugging to another system or VM. While the first part of it works without any issues, I ´m struggling to set up a working configuration for the remote debugging part. The according section in my launch.vs.json file currently looks like following (I removed the "deploy" instructions temporarily to get rid of another source of possible errors, just trying to start a gdb session with MyApp I copied there manually.):

{
  "name": "Debug MyApp on MyVM",
  "project": "CMakeLists.txt",
  "projectTarget": "MyApp",
  "type": "cppgdb",
  "disableDeploy": true,
  "debuggerConfiguration": "gdb",
  "MIMode": "gdb",
  "remoteMachineName": "-538176799;MyVM (username=root, port=22, authentication=Password)",
  "cwd": "/tmp",
  "program": "/tmp/MyApp",
  "setupCommands": [
    { "text": "-enable-pretty-printing","ignoreFailures": true }
  ]
}

When I select and launch this configuration as a startup item, the binary is built as intended inside the devcontainer, but after that I end up with an error popup with the message: Unable to find devcontainer.json.

In the Cross Platform Logging output I find:

17:12:36.8883565 [Info, Thread 1]	liblinux.RemoteSystemBase: Connecting over SSH to MyVM:22
17:12:37.1887015 [Info, Thread 47]	liblinux.Shell.CommonCommandBase: Command "cat C:\src\myapp/.devcontainer/devcontainer.json" finished with exit code 1 after 169,0114ms
17:12:37.1887015 [Info, Thread 47]	liblinux.IO.RemoteFileSystemImpl: Connecting over SFTP to MyVM:22

Looking at other liblinux.Shell log lines it seems to me these are executed inside the devcontainer and while the path to the devcontainer.json file is correct on my Windows system it looks of course differently when mounted inside the devcontainer.

So how do I need to change my configuration to get a remote debugging session started when I´m building my current target inside a devcontainer?

Developer technologies | Visual Studio | Debugging
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Surya Amrutha Vaishnavi Lanka (INFOSYS LIMITED) 1,115 Reputation points Microsoft External Staff
    2025-11-07T11:37:42.7566667+00:00

    Thanks for reaching out Based on your configuration, the error message you're facing ("Unable to find devcontainer.json") suggests that the debugger is looking for the devcontainer configuration file in the wrong path or context. Here are some steps you can take to address this issue:

    Verify Path to devcontainer.json: Ensure that the path to the devcontainer.json file is correct inside the devcontainer. When you mount the project in the devcontainer, the file structure might differ from your local Windows setup.

    1. Switch CWD (Current Working Directory): Modify the cwd property in your launch.vs.json to ensure it corresponds to the working directory inside the devcontainer where MyApp and devcontainer.json reside. For example, if the structure is like /home/user/project/myapp, set it like so
    2. Check Remote Machine Name: The remoteMachineName format you're using is a bit unusual. Make sure it matches the expected format for SSH connections.

    Environment Variables: Ensure any required environment variables that your app or the debugger expects are set in your devcontainer setup.

    Deploy Instructions: Once you've set the correct path, consider adding back your deploy instructions in the configuration. This might help to ensure everything is properly synchronized when you initialize the debugging session.

    1. Installation of Required Tools: Make sure you have gdb installed in your devcontainer, as well as any other dependencies that your application or the debugging setup might require.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.