debugging 如何将.NET7应用程序的调试器附加到VS Code上的Docker进程

pdkcd3nj  于 11个月前  发布在  .NET
关注(0)|答案(1)|浏览(182)

我试图在VS Code中调试一个在Docker容器上运行的.NET 7 web API。我试图设置launch.json文件来选择远程进程,但我不知道应该附加到哪个进程。
launch.json是这样的:

{
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickRemoteProcess}"
        }

字符串
此外,我尝试指定debuggerPath,但似乎.NET5+的应用程序不应该这样做。
有谁知道如何调试这个应用程序?
编辑1:
这是我的Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 5211

ENV ASPNETCORE_URLS=http://+:5211

# 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 --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 AS build
ARG configuration=Release
WORKDIR /src
COPY ["TestDockerAttach/TestDockerAttach.csproj", "TestDockerAttach/"]
RUN dotnet restore "TestDockerAttach/TestDockerAttach.csproj"
COPY . .
WORKDIR "/src/TestDockerAttach"
RUN dotnet build "TestDockerAttach.csproj" -c $configuration -o /app/build

FROM build AS publish
ARG configuration=Release
RUN dotnet publish "TestDockerAttach.csproj" -c $configuration -o /app/publish /p:UseAppHost=false

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


Docker compose文件

version: '3.4'

services:
  testdockerattach:
    image: testdockerattach
    build:
      context: .
      dockerfile: TestDockerAttach/Dockerfile
      args:
        - configuration=Debug
    ports:
      - 5211:5211
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    volumes:
      - ~/.vsdbg:/remote_debugger:rw

bcs8qyzn

bcs8qyzn1#

在Linux中,它是dotnet,在Windows上,它将是dotnet.exe参考这里:Attach to a process running on a Docker container

相关问题