提问人:lcarvalho 提问时间:10/24/2023 最后编辑:lcarvalho 更新时间:10/25/2023 访问量:42
如何附加 .NET7 应用程序到 VS Code 上的 docker 进程
How can I attach the debugger of a .NET7 Application to a docker process on VS Code
问:
我正在尝试在 docker 容器上运行的 VS Code 中调试 .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
答:
0赞
Mehran Khan
10/24/2023
#1
在 linux 中它是 dotnet,在 Windows 上它是 dotnet.exe ref here: 附加到 Docker 容器上运行的进程
评论
0赞
lcarvalho
10/25/2023
我没有加载符号。我检查了 pdb 在容器中,但问题仍然存在
评论