
⚠️ This blog post was created with the help of AI tools. Yes, I used a bit of magic from language models to organize my thoughts and automate the boring parts, but the geeky fun and the 🤖 in C# are 100% mine.
Hi!
I always forget how to do this, so I’ll write about it for future Bruno.
If you’ve ever fought with launch.json, tasks.json, volume mounts, vsdbg installs, and random port mappings… this one’s for you.
Here’s my quick ‘n dirty step-by-step to make it work.
1) Install the bits
- Docker Desktop
- VS Code extensions: Docker and C# / C# Dev Kit
Yes, you need these for VS Code to even think about attaching a debugger.
2) Let VS Code scaffold your stuff
Skip the “hand-craft JSON” step unless you love pain.
Hit Ctrl/Cmd+Shift+P → Containers: Add Docker Files to Workspace… (or Containers: Initialize for container debugging if you already have a Dockerfile).
This will give you:
- A proper
Dockerfile tasks.jsonwithdocker-buildanddocker-run: debuglaunch.jsonwith Containers: .NET Launch
3) Hit F5
Open the Run & Debug tab, select Containers: .NET Launch, press F5.
For .NET 7+, you can even build the container with the .NET SDK directly (no Dockerfile needed) when prompted.
4) Check ports & URLs
Make sure your app listens on 0.0.0.0 inside the container.
The common pattern is:
- Expose port
8080in the container - Map host port
5000:8080 - Add
ASPNETCORE_URLS=http://+:8080
5) Get the debugger in there
When VS Code asks to copy vsdbg into the container, say Yes.
You usually don’t need to mount your whole source tree for debugging — the tools take care of it.
6) Docker Compose?
Use Containers: Add Docker Compose Files to Workspace, then run Compose Up, and attach with Containers: .NET Attach (Preview).
Don’t try to launch a Compose setup with a normal launch.json — it’s an attach-only party.
7) When breakpoints don’t hit
The usual suspects:
- You said “No” to copying
vsdbg(re-attach, say Yes) ASPNETCORE_URLS/ ports are mismatched- You broke
tasks.json/launch.jsonediting by hand - On macOS with odd errors like “dispatcher 80131534”, pin a known
vsdbgversion in your Dockerfile:
RUN apt-get update && apt-get install -y curl unzip \
&& curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v 17.0.10712.2 -l /remote_debugger
8) Sample configs (so you don’t start from scratch)
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Containers: .NET Launch",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"netCore": {
"appProject": "${workspaceFolder}/YourProject.csproj"
}
}
]
}
tasks.json (simplified idea — use the scaffolded ones)
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "netCore",
"dockerBuild": { "dockerfile": "Dockerfile", "tag": "yourapp:dev", "context": "." },
"netCore": { "appProject": "${workspaceFolder}/YourProject.csproj" }
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [ "docker-build" ],
"dockerRun": {
"containerName": "yourapp",
"ports": [ "5000:8080" ],
"env": { "ASPNETCORE_URLS": "http://+:8080" }
},
"netCore": { "appProject": "${workspaceFolder}/YourProject.csproj", "enableDebugging": true }
}
]
}
9) Big Visual Studio (the full IDE)
Right-click project → Add > Docker Support → set debug target to Docker → F5.
Visual Studio handles MSBuild, ports, and vsdbg without asking you twice.
10) Full docs and guides
- Debug .NET in containers with VS Code:
https://code.visualstudio.com/docs/containers/debug-netcore - Common container debug configs + sample
launch.json:
https://code.visualstudio.com/docs/containers/debug-common - Docker Compose + debugging:
https://code.visualstudio.com/docs/containers/docker-compose - Blog – Debugging .NET containers with VS Code Docker Tools:
https://devblogs.microsoft.com/dotnet/debugging-dotnet-containers-with-visual-studio-code-docker-tools/ - Visual Studio – Container Tools overview:
https://learn.microsoft.com/en-us/visualstudio/containers/overview?view=vs-2022 - Visual Studio – Edit/refresh while debugging containerized apps:
https://learn.microsoft.com/en-us/visualstudio/containers/edit-and-refresh?view=vs-2022
💬 If you’ve got your own tips for debugging .NET in containers (especially for gnarly multi-container setups), drop them in the comments — I’ll happily steal them for the next update 😁
Happy coding!
Greetings
El Bruno
More posts in my blog ElBruno.com.
More info in https://beacons.ai/elbruno
Leave a reply to Dew Drop – August 14, 2025 (#4476) – Morning Dew by Alvin Ashcraft Cancel reply