Failed to launch debug adapter, when starting Docker-compose in Visual Studio 2019?

3

I have a Visual Studio solution in which I want to run various API microservices. Each microservice has the required Dockerfiles individually. I want to run the project using docker-compose, so I added container orchestration support. I also modified the necessary things in the docker-compose.yml and override files. I then set up docker-compose as the Startup Project. (Set as Startup Project). However, when I try to start with F5, the debugger does not start and I get the following error message:

Error message window

One or more errors occured. Failed to launch debug adapter. Additional information may be available in the output window. The operation was canceled.

Output window:

The program '' has exited with code -1 (0xffffffff).

On the Docker Desktop I can see the containers, but my API projects' logs are empty. They won't start.

(I have virtualization and HyperV enabled too.)

How could this problem be solved?

visual-studio
docker
api
docker-compose
containers
asked on Stack Overflow Mar 18, 2021 by TomSoldier • edited Mar 19, 2021 by helvete

1 Answer

0

According to Microsoft, by default the debugger runs in Fast Mode to speed up the building process of your docker containers. In this mode, your Dockerfile is only partially built.

https://docs.microsoft.com/en-us/visualstudio/containers/container-build?view=vs-2019

In Fast mode, Visual Studio calls docker build with an argument that tells Docker to build only the base stage. Visual Studio handles the rest of the process without regard to the contents of the Dockerfile. So, when you modify your Dockerfile, such as to customize the container environment or install additional dependencies, you should put your modifications in the first stage. Any custom steps placed in the Dockerfile's build, publish, or final stages will not be executed.

This means that if you bring in any other image in your Dockerfile before the image you are using for your runtime, it will try to use this image for your container.

Solution

  1. If you want to keep all the steps in your Dockerfile, while still being able to debug, bring your runtime image in at the top of the file and still use it where you need it. For example:
FROM mcr.microsoft.com/dotnet/aspnet:3.1 as base 
...
FROM base
WORKDIR /src
...
  1. Alternatively you can add a PropertyGroup item to your project file, telling it to build the docker file in Regular Mode. This will slow down your builds.
<PropertyGroup>
   <ContainerDevelopmentMode>Regular</ContainerDevelopmentMode>
</PropertyGroup>

Reproducing the error

I verified this by creating a new empty .NET core project with Docker Support and Container Orchestration.

The original dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["TestApplication/TestApplication.csproj", "TestApplication/"]
RUN dotnet restore "TestApplication/TestApplication.csproj"
COPY . .
WORKDIR "/src/TestApplication"
RUN dotnet build "TestApplication.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "TestApplication.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestApplication.dll"]

Runs fine. When adding a different image, node in this case, at the top of the Dockerfile, the debugger breaks:

FROM node:14-alpine as node-base

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["TestApplication/TestApplication.csproj", "TestApplication/"]
RUN dotnet restore "TestApplication/TestApplication.csproj"
COPY . .
WORKDIR "/src/TestApplication"
RUN dotnet build "TestApplication.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "TestApplication.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestApplication.dll"]
answered on Stack Overflow May 18, 2021 by einz

User contributions licensed under CC BY-SA 3.0