Attaching to remote docker container
  rxEd1anVTirq 2023年12月07日 19 0

Attaching to a docker container is quite similar to attaching to a process, the different part is that you need to select the corresponding connection type and connection target.

You may encounter the following issues when debugging with the attached docker container.

1. Unable to find debugger script at '/root/.vs-debugger'

This is usually because the vs-debugger is not installed, and can be resolved with the following commands. 

docker exec -u root <container-name> sh -c "apt-get update && apt-get install wget -y"
docker exec <container-name> sh -c "mkdir -p ~/.vs-debugger; wget https://aka.ms/getvsdbgsh -O ~/.vs-debugger/GetVsDbg.sh; chmod a+x ~/.vs-debugger/GetVsDbg.sh"

2. 'The breakpoint will not currently be hit' warning

Check the docker file, the image is built and published to 'Release' by default, it needs to be 'Debug' for debugging purposes, which is the most common mistake. You could also introduce a build/publish mode ARG, and make it configurable, for example

In the docker file define ARG 'Mode'

.......

ARG Mode=Debug
RUN echo "$Mode"

COPY ["xxx.csproj", "xxx/"]
RUN dotnet restore "xxx.csproj"
COPY . .
WORKDIR "/src/xxx"
RUN dotnet build "xxx.csproj" -c $Mode -o /app/build

FROM build AS publish
RUN dotnet publish "xxx.csproj" -c $Mode -o /app/publish /p:UseAppHost=false

.........

Then in the docker-compose file, assign the Mode with Debug or Release.

services:
  app:
    image: xxx:latest
    build: 
      context: .
      dockerfile: Dockerfile
      args:
        - Mode=Debug

3. Breakpoints look all right but can be hit anyway.

This is usually more complicated, but there are a few checkpoints you could start with.

a. Check the Debug->Windows->Mudules, and make sure the required symbols are loaded. Sometimes the list is empty, no worry, it's loading, and the breakpoint will work when it's all loaded.

 b. Set <DebugType>full</DebugType> to avoid code optimization.

 

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月07日 0

暂无评论

推荐阅读
  o1ZcTI9mJsxK   2024年04月15日   63   0   0 代码与软件发布
  bWqO7ATbLQET   2024年02月27日   47   0   0 代码与软件发布
rxEd1anVTirq