microsoft / DockerTools

Tools For Docker, including Visual Studio Provisioning and Publishing
Other
173 stars 26 forks source link

Debug with docker compose and custom dockerfile location #343

Closed dominikjeske closed 1 year ago

dominikjeske commented 2 years ago

Yesterday I lost whole day trying to figure out why I can't debug my project (ASP.NET core web api) with docker compose and VS 2022 17.2.4 - after some research I found this https://developercommunity.visualstudio.com/t/debugger-silently-fails-to-attach-to-docker-compos/552563 with statement " In summary, the Visual Studio Docker Compose tools will attach to containers only if the Dockerfile is directly adjacent its corresponding project file" and I have docker file in parent folder of csproj I have some problems with this:

  1. This behavior is not presented in documentation or I'm missing something?
  2. There is no information in logs saying that debugger is not attach because of this
  3. Since this release https://devblogs.microsoft.com/visualstudio/visual-studio-2019-v16-10-preview-2/#run-launch-services-defined-in-your-compose-files - there is lunchsetting so developer can decide when debugger should be enabled so I don't understand current behavior
  4. Docker compose lunch settings hides "StartDebugging" with no info - it is simply not visible

Are there any plans for changing this behavior? If not it should be at least better documented and tooling should inform about this in some way.

DanBiscotti commented 1 year ago

I agree this tripped me up as well. If you can specify the location of the Dockerfile then it should be possible to debug with it in the specified location

ggirard07 commented 1 year ago

Does anybody have a solution/workaround to share a single Dockerfile in parent folder for multiple .csproj while still maintaining debugging through .dcproj functional? Would be super covenant for microservices architecture...

dominikjeske commented 1 year ago

Hmm only symbolic link comes to my mind but i'm not sure it will work and how git will work with this

ggirard07 commented 1 year ago

As a follow-up, tried to link my dotnet project to compose service by specifying build.labels with com.microsoft.visual-studio.project-name: "My.Project" in either docker-compose.yml or docker-compose.vs.debug.yml, but still no luck.

This is really annoying as we are adding more and more services to existing solution while Dockerfile keeps getting more and more complicated with multi-stage, hardening, testing, external tooling support, ...

NCarlsonMSFT commented 1 year ago

@ggirard07, @dominikjeske, @DanBiscotti Visual Studio 2022 17.5 Preview 2 now allows for specifying the label com.microsoft.visual-studio.project-name on a service to specify the associated project. For instance:

  webapplication2:
    image: ${DOCKER_REGISTRY-}webapplication2
    labels:
      com.microsoft.visual-studio.project-name: "WebApplication2"
    build:
      context: .
      dockerfile: WebApplication2/Sub/Dockerfile

Allows for debugging WebApplication2 even though the Dockerfile is in a subfolder.

Note: the label can only be set in docker-compose.yml or docker-compose.override.yml

dbreshears commented 1 year ago

This is now fixed in 17.5. Closing