使用 'Docker .NET Core Attach' 进行调试不再有效
Debugging with 'Docker .NET Core Attach' not working anymore
我有几个 ASP.NET 核心 (6.0) WebApi 项目,它们使用 docker-compose docker 化。对于本地开发,我使用 docker-compose 文件,该文件引用 Docker 在调试模式下构建/发布项目的文件。然后为了调试,我使用 'Docker .NET Core Attach (Preview)' 启动配置和 select 相应的 docker 容器,然后提示我将 .NET Core 调试器复制到容器中。
直到最近,这一直有效,我可以在容器内进行调试。现在突然提示我尝试将调试器复制到容器中后,我总是得到以下错误:
Starting: "docker" exec -i web_roomservice /remote_debugger/vsdbg
--interpreter=vscode
Error from pipe program 'docker': FATAL ERROR: Failed to initialize dispatcher with error 80131534
The pipe program 'docker' exited unexpectedly with code 255.
我尝试重新安装 Docker Engine + docker-compose(最新版本),重新安装 VS Code + 'Docker' 和 'C#'扩展,从 ASP.NET Core 5.0 迁移到 6.0(因为不再支持 5.0)并且显然多次重建我的图像,但似乎没有任何效果,我在网上找不到任何东西。对此的任何帮助将不胜感激,因为到目前为止我无法调试这很糟糕。
这些是我的 docker-compose、Debug-Docker文件和启动配置(针对一个项目/服务):
version: "3.7"
services:
roomservice:
image: web_roomservice
container_name: web_roomservice
build:
context: ./
dockerfile: Dockerfile.RoomService.Debug
expose:
- "5011"
volumes:
- /etc/localtime:/etc/localtime:ro
environment:
- ASPNETCORE_ENVIRONMENT=Development
user: "root:root"
logging:
driver: "json-file"
options:
max-size: "5m"
(还有更多,但我只包含了这项服务的部分)
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
#EXPOSE 5011
ENV ASPNETCORE_URLS=http://+:5011
# Install netpbm which is used for .pgm to .png file conversion for map images
RUN apt-get -y update --silent
RUN apt-get -y install netpbm --silent
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["RoomService/RoomService.csproj", "./RoomService/"]
COPY ["EventBusRabbitMQ/EventBusRabbitMQ.csproj", "./EventBusRabbitMQ/"]
COPY ["Common/Common.csproj", "./Common/"]
RUN dotnet restore "RoomService/RoomService.csproj"
COPY RoomService ./RoomService
COPY EventBusRabbitMQ ./EventBusRabbitMQ
COPY Common ./Common
WORKDIR "/src/RoomService"
RUN dotnet build "RoomService.csproj" -c Debug -o /app/build
FROM build AS publish
RUN dotnet publish "RoomService.csproj" -c Debug -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "RoomService.dll"]
(此 Docker 文件放置在工作区文件夹(实际 RoomService 项目文件夹的父文件夹)中,以便包含 Common 项目)
{
"version": "0.2.0",
"configurations": [
{
"name": "Docker .NET Core Attach (Preview)",
"type": "docker",
"request": "attach",
"platform": "netCore",
"sourceFileMap": {
"/src/RoomService": "${workspaceFolder}"
}
}
]
}
(此启动配置位于实际 RoomService 项目文件夹的 .vscode 子文件夹中)
今天遇到了同样的问题。如果您使用的是 MacOS,请尝试删除 ~/vsdbg 目录。
大卫是对的。我有同样的问题。我是 运行 WSL2 (Ubuntu),当我删除 ~/.vsdbg
目录时,我解决了这个问题。
我有几个 ASP.NET 核心 (6.0) WebApi 项目,它们使用 docker-compose docker 化。对于本地开发,我使用 docker-compose 文件,该文件引用 Docker 在调试模式下构建/发布项目的文件。然后为了调试,我使用 'Docker .NET Core Attach (Preview)' 启动配置和 select 相应的 docker 容器,然后提示我将 .NET Core 调试器复制到容器中。
直到最近,这一直有效,我可以在容器内进行调试。现在突然提示我尝试将调试器复制到容器中后,我总是得到以下错误:
Starting: "docker" exec -i web_roomservice /remote_debugger/vsdbg --interpreter=vscode
Error from pipe program 'docker': FATAL ERROR: Failed to initialize dispatcher with error 80131534
The pipe program 'docker' exited unexpectedly with code 255.
我尝试重新安装 Docker Engine + docker-compose(最新版本),重新安装 VS Code + 'Docker' 和 'C#'扩展,从 ASP.NET Core 5.0 迁移到 6.0(因为不再支持 5.0)并且显然多次重建我的图像,但似乎没有任何效果,我在网上找不到任何东西。对此的任何帮助将不胜感激,因为到目前为止我无法调试这很糟糕。
这些是我的 docker-compose、Debug-Docker文件和启动配置(针对一个项目/服务):
version: "3.7"
services:
roomservice:
image: web_roomservice
container_name: web_roomservice
build:
context: ./
dockerfile: Dockerfile.RoomService.Debug
expose:
- "5011"
volumes:
- /etc/localtime:/etc/localtime:ro
environment:
- ASPNETCORE_ENVIRONMENT=Development
user: "root:root"
logging:
driver: "json-file"
options:
max-size: "5m"
(还有更多,但我只包含了这项服务的部分)
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
#EXPOSE 5011
ENV ASPNETCORE_URLS=http://+:5011
# Install netpbm which is used for .pgm to .png file conversion for map images
RUN apt-get -y update --silent
RUN apt-get -y install netpbm --silent
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["RoomService/RoomService.csproj", "./RoomService/"]
COPY ["EventBusRabbitMQ/EventBusRabbitMQ.csproj", "./EventBusRabbitMQ/"]
COPY ["Common/Common.csproj", "./Common/"]
RUN dotnet restore "RoomService/RoomService.csproj"
COPY RoomService ./RoomService
COPY EventBusRabbitMQ ./EventBusRabbitMQ
COPY Common ./Common
WORKDIR "/src/RoomService"
RUN dotnet build "RoomService.csproj" -c Debug -o /app/build
FROM build AS publish
RUN dotnet publish "RoomService.csproj" -c Debug -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "RoomService.dll"]
(此 Docker 文件放置在工作区文件夹(实际 RoomService 项目文件夹的父文件夹)中,以便包含 Common 项目)
{
"version": "0.2.0",
"configurations": [
{
"name": "Docker .NET Core Attach (Preview)",
"type": "docker",
"request": "attach",
"platform": "netCore",
"sourceFileMap": {
"/src/RoomService": "${workspaceFolder}"
}
}
]
}
(此启动配置位于实际 RoomService 项目文件夹的 .vscode 子文件夹中)
今天遇到了同样的问题。如果您使用的是 MacOS,请尝试删除 ~/vsdbg 目录。
大卫是对的。我有同样的问题。我是 运行 WSL2 (Ubuntu),当我删除 ~/.vsdbg
目录时,我解决了这个问题。