首页 > 解决方案 > 在 VS2019 中调试 Docker-Compose 失败并出现 .Net Core SDK 错误

问题描述

所以,我想在我的一个项目中学习并尝试 Docker-Compose。该项目由 6 个 ASP.Net Core 独立服务组成,均配备了自动生成的 dockerfile。

所有项目都在 .Net Core 3.1 上运行,它们的 dockerfile 也反映了这一点。

dockerfile 示例:

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

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY .... (Some copies here I did cut out)
RUN dotnet restore "Services/MooMed.Stateful.SessionService/MooMed.Stateful.SessionService.csproj"
COPY . .
WORKDIR "/src/Services/MooMed.Stateful.SessionService"
RUN dotnet build "MooMed.Stateful.SessionService.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "MooMed.Stateful.SessionService.csproj" -c Release -o /app/publish

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

VS 然后生成以下 docker-compose.yml:

  moomed.stateful.sessionservice:
    image: ${DOCKER_REGISTRY-}moomedstatefulsessionservice
    build:
      context: .
      dockerfile: Services/MooMed.Stateful.SessionService/Dockerfile

使用相应的 docker-compose.override.yml:

moomed.stateful.sessionservice:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=https://+:443;http://+:80
    ports:
      - "80"
      - "443"
    volumes:
      - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
      - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro

这是我在尝试调试 docker-compose 时得到的错误日志:

-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
  It was not possible to find any installed .NET Core SDKs
  Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
      https://aka.ms/dotnet-download
  It was not possible to find any installed .NET Core SDKs
  Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
      https://aka.ms/dotnet-download
  It was not possible to find any installed .NET Core SDKs
  Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
      https://aka.ms/dotnet-download
  It was not possible to find any installed .NET Core SDKs
  Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
      https://aka.ms/dotnet-download
  It was not possible to find any installed .NET Core SDKs
  Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
      https://aka.ms/dotnet-download
  It was not possible to find any installed .NET Core SDKs
  Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
      https://aka.ms/dotnet-download
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program 'dotnet' has exited with code 145 (0x91).
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program 'dotnet' has exited with code 145 (0x91).
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program 'dotnet' has exited with code 145 (0x91).
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program 'dotnet' has exited with code 145 (0x91).
The program 'dotnet' has exited with code 145 (0x91).
The program 'dotnet' has exited with code 145 (0x91).

请注意,docker-compose 确实运行了所有 6 项服务,我只列出了其中一项的文件,以便将您从文本墙中拯救出来。

但是,所有 dotnet 命令都以相同的方式失败。

我应该注意,当单独从 VS 在 Docker 中运行服务时完全没有问题,它工作得非常好,所以我认为 Dockerfiles 不一定是错误的。尽管我在 docker-compose 中阅读了有关构建部分的内容,但它也应该明确地使用给定的 Dockerfiles,就像我自己做的那样。

那么,这里可能出了什么问题?

编辑:更多信息......与此同时,我还创建了一个新的默认 Asp.Net Core 应用程序,通过 docker-compose 使用 dockerfiles 和 compose yaml 运行它,除了引用之外,它基本上等于这个,并且没有任何问题那里。

EDIT2:现在也尝试docker-compose up手动,这非常有效。这是否与 VS 中的调试组合启动功能所做的 vsdbg 相关联?我的意思是我不知道 Visual Studio 是如何做这些事情的,但可能 VS 将 yaml 转换为包含 vsdbg 的下载,然后将条目 args 提供给启动应用程序的调试器,然后这将失败,因为容器没有有必要的命令。可能是这样的。但是,如果是这种情况,那么在没有 docker-compose 的情况下对单个服务进行正常调试时也会失败。

标签: visual-studiodocker.net-coredocker-composedockerfile

解决方案


是的,好老的特殊字符问题。

罪魁祸首只是在我的文件夹结构中有一个 /C#/ 。将其重命名为 /C-Sharp/ 现在它可以工作了。


推荐阅读