hcp*_*hcp 18 .net c# docker rider wsl-2
Rider有关于如何通过 SSH 调试远程应用程序的文档,当我调试在 WSL2 上运行的应用程序时,它完美地工作。但它不适用于调试在 WSL2 内的 docker 容器中运行的应用程序。Rider 甚至在“运行”->“附加到远程进程”菜单中显示此应用程序,但无法附加到它(没有错误,但不附加)。
我可能需要在运行应用程序的 Docker 容器内运行 JetBrains SSH Server Utility 并共享端口,但我不知道如何正确执行。
编辑:为了清楚起见,我添加了一张我想要得到的结果的图表。
非常感谢任何帮助。谢谢。
以下是在 Docker 容器内远程调试 Rider 的解决方案。确切的解决方案将取决于您的具体环境以及您使用 Docker 构建的映像类型。步骤一般如下:
Dockerfileroot)entrypoint脚本,首先执行 SSH 代理,然后执行您的应用程序。entrypoint为默认值ENTRYPOINT或CMD在您的Dockerfile从那里开始,步骤与任何其他远程 SSH 连接相同。
假设您正在Dockerfile构建您的应用程序ubuntu:
Dockerfile
FROM ubuntu:18.04
WORKDIR /usr/local/app
# Copy required files including entrypoint wrapper
COPY entrypoint.sh /usr/local/bin/
RUN apt-get update && apt-get install -y curl
RUN \
# replace with the appropriate arch as needed
curl -L "https://download.jetbrains.com/rider/ssh-remote-debugging/linux-x64/jetbrains_debugger_agent_20230319.24.0" \
-o /usr/local/bin/debugger && \
chmod +x /usr/local/bin/debugger
# debugging port
EXPOSE 7777
# expose your actual application ports e.g.
# EXPOSE 80
ENTRYPOINT ["entrypoint.sh"]
Run Code Online (Sandbox Code Playgroud)
入口点.sh
FROM ubuntu:18.04
WORKDIR /usr/local/app
# Copy required files including entrypoint wrapper
COPY entrypoint.sh /usr/local/bin/
RUN apt-get update && apt-get install -y curl
RUN \
# replace with the appropriate arch as needed
curl -L "https://download.jetbrains.com/rider/ssh-remote-debugging/linux-x64/jetbrains_debugger_agent_20230319.24.0" \
-o /usr/local/bin/debugger && \
chmod +x /usr/local/bin/debugger
# debugging port
EXPOSE 7777
# expose your actual application ports e.g.
# EXPOSE 80
ENTRYPOINT ["entrypoint.sh"]
Run Code Online (Sandbox Code Playgroud)
接下来,构建包含启用了调试符号的应用程序的映像:
#!/usr/bin/env bash
/usr/local/bin/debugger -port 7777 &
# execute your actual application next
# e.g. `node index.js`
sleep 1d
Run Code Online (Sandbox Code Playgroud)
最后,启动容器:
$ docker run --rm -i -p7777:7777 jetdebug
Using host key fingerprint SHA256:ietD1qIhLzcDNcmH/dm2kp6us1j8QRa4yErNhn7vAYo
Please use these credentials to establish SSH connection:
Login: root
Password: ajpOUbr7dNLIp1gy
Port: 7777
Copy the three lines above and switch to Rider: it will detect the credentials in the clipboard and suggest adding a new remote host configuration with these login, password, and port.
Note: you will still need to specify the host name manually.
Run Code Online (Sandbox Code Playgroud)
请注意,标志指定运行容器时的
-p7777:7777转发端口。7777如果您在单独的服务器上执行此操作,则可能需要更改防火墙设置以进一步允许远程访问该端口。
我们现在可以在主机上看到端口7777已正确转发到调试 SSH 代理:
$ docker build -t jetdebug .
[+] Building 13.2s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 532B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:18.04 0.0s
=> [1/5] FROM docker.io/library/ubuntu:18.04 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 170B 0.0s
=> CACHED [2/5] WORKDIR /usr/local/app 0.0s
=> [3/5] COPY entrypoint.sh /usr/local/bin/ 0.0s
=> [4/5] RUN apt-get update && apt-get install -y curl 10.7s
=> [5/5] RUN curl -L "https://download.jetbrains.com/rider/ssh-remote-debugging/linux-x64/jetbrains_debugger_agent_20230319.24.0" -o /usr/local/bin/debugger && chmod +x /usr/local/bin/debugger 2.3s
=> exporting to image 0.2s
=> => exporting layers 0.2s
=> => writing image sha256:b98a6356808dd97fe1222892914305fcf1f47e709ac68bde41077a8a24769563 0.0s
=> => naming to docker.io/library/jetdebug
Run Code Online (Sandbox Code Playgroud)
从这里,您可以按照正常方式在 Rider 中进行远程连接。
如果您的应用程序使用不同的基础 Docker 映像,步骤是相同的,但可能需要针对所涉及的操作系统和架构进行调整。
逻辑entrypoint显然可以用任何语言编写。
另请注意,此设置包含多种反模式,永远不会推荐用于任何类型的生产部署。除了调试符号不应该出现在生产代码中这一事实之外,容器还应该只包含一个关注点,并且调试 SSH 进程不会受到该docker进程的监控,以防它意外崩溃。
| 归档时间: |
|
| 查看次数: |
4172 次 |
| 最近记录: |