-
Notifications
You must be signed in to change notification settings - Fork 64
Debug .NET Core with docker containers #130
Comments
For my own exercise, I went through the
|
Hey @MichaelSimons I got it to work. However there are limitations with the current approach:
I think those two painpoints are a joint work between the generator-docker and the VSCode debugger... |
We also, need the the docker file to load the new 1.8 C# extension debugger. From (https://github.com/OmniSharp/omnisharp-vscode/blob/v1.8.0/CHANGELOG.md)
|
@matthewjcooper I had the precisely same problem yesterday. Had to change everything to use |
@galvesribeiro would you mind sending me what you did to get working, i'm having issues. |
@matthewjcooper I'm not using this template anymore because it is very limited and rely on external and platform specific issues. So what I have is: Dockerfile:
Solution level version: '3.1'
services:
YOU_PROJECT:
image: YOUR_PROJECT:debug
build:
context: ./src/YOU_PROJECTDIRECTORY_HERE/bin/PublishOutput/
dockerfile: Dockerfile.debug
ports:
- "10200:10200"
environment:
- ASPNETCORE_ENVIRONMENT=Development
volumes:
- ./src/YOU_PROJECTDIRECTORY_HERE/bin/PublishOutput/:/app
- ~/.nuget/packages:/root/.nuget/packages:ro VSCode {
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "publish",
"args": [
"${workspaceRoot}/YOUR_SOLUTION.sln", "-c", "Debug", "-o", "bin/PublishOutput"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
} VSCode {
"version": "0.2.0",
"configurations": [
{
"name": "YOUR_PROJECT",
"type": "coreclr",
"request": "launch",
"cwd": "/app",
"program": "/app/YOUR_PROJECT.dll",
"sourceFileMap": {
"/app": "${workspaceRoot}/src/YOUR_PROJECTDIRECTORY"
},
"pipeTransport": {
"debuggerPath": "/vsdbg/vsdbg",
"pipeProgram": "/bin/bash",
"pipeCwd": "${workspaceRoot}",
"pipeArgs": [
"-c",
"docker exec -i YOUR_PROJECT_1 /vsdbg/vsdbg --interpreter=vscode"
]
}
}
]
} To make it work:
Every time you make change to the code you just need to build the project again (which will effectively publish whole solution) and run. Note that you can run multiple projects but not at same tiem. For wharever reason the VSCode setting to start multiple projects don't work while remote debugging. That doesn't prevent you to hit Start button in the second config so both debugger are running live. Limitations: You can't use Note that I'm not using any magical Let me know if you have any issues. UPDATE: I forgot to mention that you must be on VSCode with the C# extension on version 1.8.0 or superior. If for whatever reason you need to keep pre-1.8.0, please update the example to use |
Also, that config circumvent all limitations of the Docker extensions of VSCode since it only adds the syntax highlight so you don't need it if you don't want and is more flexible than recent released VS2017 Docker tools which is a lot more limited. |
Wow, thanks for the quick reply, I’ll give this a shot!
|
This is working great. I also added "preLaunchTask": "publish", so I don't forget to rebuild when I make changes. |
Yeah, I forgot to mention that... The Glad it worked! |
Last issue i'm having, is that the problem matcher is showing the problems, but clicking on them is not able to find the actual source file to pull up. Is there a way to change the cwd path for the problem matcher? "problemMatcher": "$msCompile" |
Hummm... No idea... Is that really related to the debugger? Because IIRC it is related to the compiler and language services, right? |
You are right, not related to debugging, just how to link compile errors/warning with the vscode problems window. Nvm on that one. |
It would be nice if there was a sample project setup to include these changes, or even a forked repo to demonstrate this. I had hoped that this project would've resolved this by now, but it seems like that is not the case. Anyone willing to set something up that they have working or work on forking this? I'd be willing to chip in, but running these instructions; when attaching to debugger, it looks like VSCode just keeps doing something and sits in limbo. |
I'm pretty early in my understanding of Docker, as is my team, but right now we develop locally, then deploy to a local docker and then deploy to production (process simplified--there's a but more change and source control involved). We'd certainly love to do away with that first phase and simply do everything always in Docker, and despite all of us having MSDN accounts, almost all of us have moved from VS to VS Code. It's wonderful besides the debugging within Docker part. 👍 |
I was running into a bunch of issues with either nothing happening, or debugger kept breaking on start. My issue was actually that I was on the C# extension v1.7. VSCode was not telling me I had an updates available, but looking in the extensions view, I could see 1.7.0. I just upgraded to 1.8.0 and everything worked fine. Thanks for the solution @galvesribeiro |
I've implemented @galvesribeiro workflow in a sample repo, and at first it's seems to be working correctly. But when I call the web service it does not respond. The difference I see from what I normally do is When running the docker debug workflow I get an output saying that the application is started
and
Does anyone have an idea why the application is not triggering on port 6000 even though it seems to be open? |
@bialad you have to set the proper ports on your The reason I'm using If you do the way you are suggesting, every time you start a debug session you need to spin up a new container. Like I mentioned before, to make it work on windows server containers, just change the base image and the entrypoint to something similar in powershell/cmd. So, to fix your case, just change this:
To this:
And it should work for you. |
Yeah, sorry, I forgot to mention that my sample is valid on VSCode with C# Extensions 1.8.0+. Starting this version, they replaced the old However, it should work exactly same as before. You just have to change the I strongly recommend to update the extension to 1.8.0. |
@galvesribeiro I figured I needed to do that, so I did. You can see my config in the repo, or in the docker-compose.yml specifically. Keeping the container running and restarting the application is a neat trick, that's one reason I really like to get this running. :) Do you need to do anything different in your application? I use My host is running Ubuntu 16.04, docker version 17.03.0-ce, dotnet cli version 1.1, C# extension 1.8.0 if that differs from your setup. |
Yeah, make sure |
That worked! Thanks @galvesribeiro Also I'll update the repo if anyone's interested in the result. |
There are no a definitive steps to get success? |
@alexsandro-xpt what you mean? did you tried my example? It work perfectly for us here... |
@galvesribeiro that example #130 (comment) ? I tried setup it at my project right now but your files there are a lot of words of or soluction like |
@alexsandro-xpt Try this. It's very simple and what I successfully use for several of my projects. |
@bialad, I have tried, I not clone this repository, only just changed vscode files and docker files. |
@alexsandro-xpt man, it is extremely simple to replace project name in that example. You can try @bialad repo which is the exactly same code with simpler names if you prefer... However, its important to mention that it is for Visual Studo Code(VSCode) and not Visual Studio 2017. VS2017 has its own extension for docker debugging but IMHO, it is very weird and dont allow you debug multiple projects neither multiple instances of the same service. VSCode one in other hand, allow you to easily debug multiple projects easily BUT, it still need some work (which I plan to do) to debug multiple instances of the same container. Both the cases need some work to get proper debugging on multiple instances of the same process. |
Alright @galvesribeiro, I will try it too late, the trully is I tried set up it quickly but in another time I will try better. Thank you and @bialad to reply! |
Why @galvesribeiro and @bialad use |
@alexsandro-xpt because all we use is .net core. I have no idea what is the difference with aspnetcore one is... In fact, it is a lot confusing... |
@galvesribeiro I found this post https://blogs.msdn.microsoft.com/stevelasker/2016/09/29/building-optimized-docker-images-with-asp-net-core/ may it can help us to do a better work. |
Could I change pipeProgram to |
Absolutely. It work the wane way on Windows with both Powershell and CMD.
|
Hmm, I get this issue when I try to debug within VS code using
Any ideas? Thanks. |
@raRaRa I had the same issue, did you tried using powershell instead? Another thing I noticed is that the
Hope this helps! |
I struggled for some time with this, trying to update the files created by the yeoman generator. I'm using a Mac and the following
Note I still use the yeoman-generated dockerTask.sh for building/composing the application. |
@daveclarke yeah, it may work. I just don't want to depend on a script if I can avoid it. |
@galvesribeiro I agree - I spent some time trying to get the yeoman generated files to work for my project with only limited success. Right now, using your template, it's working and I need to move onto something else but will definitely be coming back to refactor. |
The only problem I see today is that neither VS or VSCode is able to debug multiple instances of the same container... lets say, a Service which has multiple replicas and you want to debug them in parallel... But that is probably something that we should ask in another issue. |
Hi Guys! I just wanted to try to contribute to get this debugging and docker setup up and running faster. I created this repo -> https://github.com/akay64/aspnetcore-2.0-docker-dbg It has clear instructions and presets on how to get this running quickly. Feel free to give your feedback :)
|
@akay64 |
trying to follow advice in this issue:
Fails with: Tried to call Docker directly:
Error: The pipe program 'docker' exited unexpectedly with code 126. Any ideas? |
This works:
|
@galvesribeiro Your solution worked for me, saved my day. |
Thank you SO much for documenting this! I got it to work and am thrilled. So helpful. Thanks again. |
One thing to add to that. My sample was based on |
Good to know! Thanks. |
[Copied from https://github.com/dotnet/dotnet-docker/issues/185]
What is the proper way to install the debugger on a dotnet image and get it debugging from VSCode?
Currently there are multiple (messy) ways to work with old project.json and containers like for example, that bunch of scripts generated by yo docker.
Is there any guidance on how to create a debug container for .net apps?
Thank you
@galvesribeiro
The text was updated successfully, but these errors were encountered: