在 Visual Studio 2019 中启动 Docker-compose 时无法启动调试适配器? [英] Failed to launch debug adapter, when starting Docker-compose in Visual Studio 2019?

查看:216
本文介绍了在 Visual Studio 2019 中启动 Docker-compose 时无法启动调试适配器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Visual Studio 解决方案,我想在其中运行各种 API 微服务.每个微服务都单独具有所需的 Dockerfile.我想使用 docker-compose 运行项目,所以我添加了容器编排支持.我还修改了 docker-compose.yml 和覆盖文件中的必要内容.然后我将 docker-compose 设置为启动项目.(设置为启动项目).但是,当我尝试使用 F5 启动时,调试器无法启动,并且收到以下错误消息:

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:

发生了一个或多个错误.无法启动调试适配器.输出窗口中可能提供其他信息.操作已取消.

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

输出窗口:

程序 '' 已退出,代码为 -1 (0xffffffff).

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

在 Docker 桌面上我可以看到容器,但我的 API 项目的日志是空的.他们不会开始.

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

(我也启用了虚拟化和 HyperV.)

(I have virtualization and HyperV enabled too.)

如何解决这个问题?

推荐答案

根据 Microsoft 的说法,默认情况下调试器以 快速模式 运行,以加快 docker 容器的构建过程.在这种模式下,您的 Dockerfile 只是部分构建.

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

在快速模式下,Visual Studio 使用一个参数调用 docker build,该参数告诉 Docker 仅构建基础阶段.Visual Studio 处理其余的过程,而不考虑 Dockerfile 的内容.因此,当您修改 Dockerfile 时,例如自定义容器环境或安装其他依赖项,您应该将修改放在第一阶段.将不会执行 Dockerfile 的构建、发布或最终阶段中的任何自定义步骤.

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.

这意味着,如果您在用于运行时的镜像之前在 Dockerfile 中引入任何其他镜像,它将尝试将此镜像用于您的容器.

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.

  1. 如果您想在 Dockerfile 中保留所有步骤,同时仍然能够调试,请将您的运行时映像放在文件的顶部,并仍然在需要的地方使用它.例如:

FROM mcr.microsoft.com/dotnet/aspnet:3.1 as base 
...
FROM base
WORKDIR /src
...

  1. 或者,您可以将 PropertyGroup 项添加到项目文件中,告诉它以常规模式构建 docker 文件.这会减慢您的构建速度.
  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>

重现错误

我通过使用 Docker 支持和容器编排创建一个新的空 .NET 核心项目来验证这一点.

Reproducing the error

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

原始dockerfile:

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"]

运行良好.当在 Dockerfile 顶部添加不同的图像时,在这种情况下为节点,调试器中断:

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"]

这篇关于在 Visual Studio 2019 中启动 Docker-compose 时无法启动调试适配器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆