Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instructions on remote debugging with Docker? #1369

Closed
kikkoi opened this issue Apr 7, 2017 · 13 comments
Closed

Instructions on remote debugging with Docker? #1369

kikkoi opened this issue Apr 7, 2017 · 13 comments
Assignees
Milestone

Comments

@kikkoi
Copy link

kikkoi commented Apr 7, 2017

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.

@rajkumar42 rajkumar42 assigned rajkumar42 and WardenGnaw and unassigned rajkumar42 Apr 7, 2017
@rajkumar42
Copy link
Contributor

@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"
            }
        }

@kikkoi
Copy link
Author

kikkoi commented Apr 7, 2017

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?

@WardenGnaw WardenGnaw added this to the 1.9 milestone Apr 11, 2017
@WardenGnaw
Copy link
Contributor

@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

@herecydev
Copy link

herecydev commented Apr 24, 2017

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

@gregg-miskelly
Copy link
Contributor

@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

@herecydev
Copy link

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

@gregg-miskelly
Copy link
Contributor

@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
            }
        },

@herecydev
Copy link

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?

@gregg-miskelly
Copy link
Contributor

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).

@chrisdias
Copy link
Contributor

@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

@herecydev
Copy link

@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.

@sleemer
Copy link

sleemer commented Aug 16, 2017

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

@lawphotog
Copy link

lawphotog commented Sep 13, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants