vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Instructions on remote debugging with Docker?

Open kikkoi opened this issue 9 years ago • 13 comments

Environment data

dotnet --info output: .NET Command Line Tools (1.0.0) Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\1.0.0

VS Code version: 1.11.0 C# Extension version: 1.8.1

Steps to reproduce

  1. Build the dockerfile and launch a container.
FROM microsoft/aspnetcore:1.1.1

WORKDIR /vsdbg
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
unzip \
&& rm -rf /var/lib/apt/lists/* \
&& curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /vsdbg

  1. Set up launch.json
{
  "name": ".NET Core Remote Attach",
  "type": "coreclr",
  "request": "attach",
  "pipeTransport": {
    "pipeProgram": "C:\\windows\\system32\\cmd.exe",
    "pipeArgs": [ "/c", "docker.exe exec -i 19cccb6eff57"  ${debuggerCommand}"],
    "debuggerPath": "~/vsdbg/vsdbg",
    "pipeCwd": "${workspaceRoot}",
    "quoteArgs": false
  },
  "sourceFileMap": {
    "/Views": "${workspaceRoot}/Views"
  }
}

Expected behavior

Start debug. Throw error "Starting: "C:\windows\system32\cmd.exe" /c docker.exe exec -i c3e211ef953f vsdbg --interpreter=vscode" in Debug console. Too I tried before writing docker exec in CMD and didn't work out so well.

C:\Users\Test>docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c3e211ef953f propro "/bin/bash" 12 minutes ago Up 12 minutes nifty_feynman

C:\Users\Test>docker exec -i c3e211ef953f ~/vsdbg/vsdbg --interpreter=vscode rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: "~/vsdbg/vsdbg": stat ~/vsdbg/vsdbg: no such file or directory"

C:\Users\Test>docker exec c3e211ef953f /bin/bash -c "echo worked well" worked well

I'd be thankful if you could instruction on this. Because can't find something in good instruction for remote debugging with Docker.

kikkoi avatar Apr 07 '17 08:04 kikkoi

@kikkoi we have a fix on the way, meanwhile please use this config as an example

       {
            "name": ".NET Core Remote Attach",
            "type": "coreclr",
            "request": "attach",
            "processId":12345,
            "pipeTransport": {
                "pipeProgram": "docker",
                "pipeArgs": [ "exec", "-i", "90d6d355c37c"],
                "debuggerPath": "~/vsdbg/vsdbg",
                "pipeCwd": "${workspaceRoot}",
                "quoteArgs": false
            },            
            "sourceFileMap": {
                "/Views": "${workspaceRoot}/Views"
            }
        }

rajkumar42 avatar Apr 07 '17 17:04 rajkumar42

Followed the example. I'm having issue that error "The pipe program 'docker' exited unexpectedly with code 126" and doing nothing. http://imgur.com/a/MbJvt I put a wrong the container (like testing) and throws well

Starting: "docker" exec -i wrong ~/vsdbg/vsdbg --interpreter=vscode Error from pipe program 'docker': Error response from daemon: No such container: wrong

What am I doing wrong? or it's bug?

kikkoi avatar Apr 07 '17 19:04 kikkoi

@kikkoi I have made a fix with #1373. This will be available in our next release.

For your bug. I believe the debuggerPath in your configuration should be: "/vsdbg/vsdbg" if you ran curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /vsdbg

WardenGnaw avatar Apr 11 '17 17:04 WardenGnaw

Any chance we can get some definitive examples on this? I came up with the following:

{
            "name": "Debug Api",
            "type": "coreclr",
            "request": "attach",
            "sourceFileMap": {
                "/app": "${workspaceRoot}/src/Api"
            },
            "processName": "dotnet",
            "pipeTransport": {
                "debuggerPath": "/vsdbg/vsdbg",
                "pipeProgram": "powershell",
                "pipeCwd": "${workspaceRoot}",
                "pipeArgs": [
                    "-c",
                    "docker exec -i api_1"
                ]
            }
        },

Which works (there's definitely some oddities but I think that's vscode/vsdbg related). But as you can see I have to hard code the specific container I want. Is there a way we can interrogate the running containers and show a picker (just like the docker extension for vscode)? More than happy to do the leg work here but not sure where to start

herecydev avatar Apr 24 '17 07:04 herecydev

@chrisdias: Is there a generic 'docker container chooser` that the docker extension provides that @herecydev can use in his launch.json?

CC @glennc @Andrew-MSFT

gregg-miskelly avatar Apr 24 '17 16:04 gregg-miskelly

@gregg-miskelly Is vsdbg (as I'm doing it) still the recommend way of debugging containers?

herecydev avatar Apr 24 '17 16:04 herecydev

@herecydev you will definitely need to run vsdbg. But I don't think there is any reason to use powershell any longer. Does this work? (NOTE: this requires the 1.9 version of the extension)

{
            "name": "Debug Api",
            "type": "coreclr",
            "request": "attach",
            "sourceFileMap": {
                "/app": "${workspaceRoot}/src/Api"
            },
            "processName": "dotnet",
            "pipeTransport": {
                "debuggerPath": "/vsdbg/vsdbg",
                "pipeProgram": "docker",
                "pipeCwd": "${workspaceRoot}",
                "pipeArgs": [
                    "exec", "-i", "api_1"
                ],
                "quoteArgs": false
            }
        },

gregg-miskelly avatar Apr 24 '17 17:04 gregg-miskelly

Can't try until tomorrow but looks solid. There's 2 problems that need smoothing out

  1. As above, debugging api_2, api_3, etc isn't possible without manually changing the launch.json
  2. Is it possible to have PDBs in the container itself. I'm after "embedding" them alongside images in the hope that you can debug containers with older tags easier. Is this a thing? Will it be able to reconcile differences with your codebase?

herecydev avatar Apr 24 '17 18:04 herecydev

For 2: vsdbg needs the PDBs inside the container. But you would likely want to sync your enlistment to the code you are trying to debug (or point your sourceMap to some other copy of the code that is in-sync with what you are debugging).

gregg-miskelly avatar Apr 24 '17 20:04 gregg-miskelly

@gregg-miskelly no there is no generic 'docker container chooser' in the docker extension. Code is simple though, see here: https://github.com/Microsoft/vscode-docker/blob/master/commands/utils/quick-pick-container.ts#L40

chrisdias avatar Apr 24 '17 21:04 chrisdias

@chrisdias Is this something you are looking to support in the extension itself? Feels like something that many people would benefit from. Not sure how to untie it from specifically .net though.

herecydev avatar Apr 25 '17 12:04 herecydev

I know that the issue was closed, but I thinks there's still something to say about remote debugging with omnisharp. There's no proper wiki page that will tell us how to setup vscode, omnisharp and our project to be able not only debug in Docker container, but also build the whole app in Docker container (that will allow us not to install every version of dotnet sdk on the host machine). So, I've created some sample repo where I set up all the pieces to be able to build and debug in Docker container. Hope this helps. https://github.com/sleemer/docker.dotnet.debug

sleemer avatar Aug 16 '17 19:08 sleemer

I know this is an old issue but as I landed on this page while setting my dotnet core app inside docker container so for anyone new looking for a solution. I have been doing vsdbg approach. But now I switched to using Remote - Containers extension of VS Code and reinstall OmniSharp once your VS Code is installed inside the container. It works really well for me. It needs a bit of set up to get started but this is the way forward developing dotnet core app with docker. for more information please see this link. https://code.visualstudio.com/docs/remote/containers

lawphotog avatar Sep 13 '19 16:09 lawphotog