debugging doesn't work for docker compose with visual studio
Edit2:
Patch for Visual Studio (16.11.6+) was released.
You can docker-compose enable-v2
now.
This answer is now obsolete.
For random googlers, there is new issue (October/November 2021) in docker-compose
which broke Visual Studio 2019 (but not VS2022 preview) debugging with almost the same symptoms as in this question.
The thing is, docker-compose config
will return relative path to Build.Context
and Build.Dockerfile
(it should return absolute path in Build.Context
and relative in Build.Dockerfile
)
Solution right now is docker-compose disable-v2
and Clean & Rebuild your solution until new docker-compose or visual studio patch is released.
For details, see https://github.com/microsoft/DockerTools/issues/311 and https://github.com/docker/compose/issues/8760
Edit:
The next VS update is on Nov 9th [2021]. It will have the fix.
I found out what was going wrong. The answer is the solution to the question posted here. https://developercommunity.visualstudio.com/content/problem/552563/debugger-silently-fails-to-attach-to-docker-compos.html
Basically when a dockerfile is NOT next to (adjacent to) the corresponding csproj file (project file), visual studio will not attach the debugger. This is by design because there might be containers that you want to start but not want to debug (reverse proxy, mysql database, etc..). So When I moved my Dockerfile for the api inside the restapi folder (the same folder as the csproj file) and adjusted my docker-compose.yml to look for a dockerfile inside that folder debugging worked in visual studio.