.netdockervisual-studio.net-core

Debugging with Docker in Visual Studio 2022 fails when editing Dockerfile


I set up a project that allows debugging in a Linux docker container in Visual Studio 2022. Now, I wanted to add a stage prior to the build stage. For the sake of simplicity I just show a simplified version using some dummy alpine stage.

Extract from Dockerfile

This gives me the following error when trying to debug:

Debugging Error

Docker command failed with exit code 127. docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec "dotnet": executable file not found in $PATH: unknown. If the error persists, try restarting Docker Desktop.

Error message

Note: This works if I switch to 'Release' - but I want to make use of the debugging facilities.

What can I do?


Solution

  • You need to set the project property DockerfileFastModeStage to base :

    <PropertyGroup>
      <DockerfileFastModeStage>base</DockerfileFastModeStage>
    </PropertyGroup>
    

    For "fast mode" the tools use whatever is the first stage by default so adding your stage to the top means it's attempting to use the now empty stage.


    Alternatively: You can set ContainerDevelopmentMode to Regular:

    <PropertyGroup>
      <ContainerDevelopmentMode>Regular</ContainerDevelopmentMode>
    </PropertyGroup>
    

    to have VS build the entire Dockerfile for debugging (Release mode does this by default).