Here is how to configure VS Code for line-by-line debugging a .NET Core 2.1 application in a Docker container
-
Start microsoft/dotnet:2.1-sdk interactively
docker run --rm -it \ -v ${PWD}:/app \ -w /app \ -p 5000:5000 \ --name my-app \ --hostname dotnet \ microsoft/dotnet:2.1-sdk
-
Install the debugger files needed for remote debugging inside the continer
apt-get update && apt-get install -y unzip curl -sSL https://aka.ms/getvsdbgsh | \ /bin/sh /dev/stdin -v latest -l ~/vsdbg
-
Create a new web project with dotnet new web -n web.
-
Add the following line to the Program class:
.UseUrls("http://*:5000")
-
Run the application inside the container:
dotnet run -p web
-
Add the following launch command to the launch.json file in VS Code:
{ "name": ".NET Core Docker Attach", "type": "coreclr", "request": "attach", "processId": "${command:pickRemoteProcess}", "pipeTransport": { "pipeProgram": "docker", "pipeArgs": [ "exec", "-i", "my-web" ], "debuggerPath": "/root/vsdbg/vsdbg", "pipeCwd": "${workspaceRoot}", "quoteArgs": false }, "sourceFileMap": { "/app/web": "${workspaceRoot}/web" }, "logging": { "engineLogging": true } }
-
In VS Code switch to the debugger pane
-
Select the correct debug configuration from the dropdown (.NET Core Docker Attach)
-
From VS Code launch the debugger by hitting the green right arrow in the debugger
-
In the drop down select the correct process. The process should be looking like this:
dotnet <process ID> dotnet exec /app/web/bin/Debug/netcoreapp2.1/web.dll
Where in my case
<process ID>
is equal to629
, but this will be different in your case -
Set a break point in the Startup class at line 30.
-
From the host do a
curl localhost:5000
and notice that the break point is hit.
Hi,
shouldn't the 2 values in lines:
--name my-app
and
"pipeArgs": [ "exec", "-i", "my-web" ],
be the same (either both my-app or both my-web)?