加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Visual Studio代码 – 如何在Docker容器中远程调试python代码

发布时间:2020-12-16 03:35:32 所属栏目:安全 来源:网络整理
导读:我试图在VSC中远程配音python: 它是main.py文件: print('Hello,World') debug.py: import ptvsdptvsd.enable_attach('my_secret',address=('0.0.0.0',7102))ptvsd.wait_for_attach() Dockerfile: FROM python:3.6-slimEXPOSE 7102RUN pip install ptvsdW

我试图在VSC中远程配音python:

它是main.py文件:

print('Hello,World')

debug.py:

import ptvsd
ptvsd.enable_attach('my_secret',address=('0.0.0.0',7102))
ptvsd.wait_for_attach()

Dockerfile:

FROM python:3.6-slim

EXPOSE 7102

RUN pip install ptvsd

WORKDIR /app

COPY . .

CMD ["python","debug.py"]

它是launch.json文件:

{
    "version": "0.2.0","configurations": [
        {
            "name": "Attach (Remote Debug)","type": "python","request": "attach","localRoot": "${workspaceRoot}","remoteRoot": "/app","port": 7102,"secret": "my_secret","host": "172.17.0.3"
        }
    ]
}

这是一个构建和启动容器的命令:

docker build -t python-for-debug .

docker run -it -p 7102:7102 python-for-debug

当我运行调试器时,我得到:
screen of vs code

调试控制台没有任何错误,没有输出,没有问题.没有任何输出用于运行容器.没有泊坞日志

VS Code版本:1.15.0
Docker版本17.06.0-ce,build 02c1d87

最佳答案
编辑12-AUG

我设置了一个测试版本来查看可能出错的地方.问题是Visual Studio代码在连接之前没有连接到失败的调试器

请参阅JS代码中的异常.

Visual Studio Error Log

在github上也存在一个未解决的问题

https://github.com/DonJayamanne/pythonVSCode/issues/805

您最好的选择是将这些细节添加到问题中或打开一个新问题

原答案:

您看到的行为实际上是正确的.我看到了你的截图,你在客户端脚本中打印了“Hello World”,下面的代码就是你的遥控器

import ptvsd
ptvsd.enable_attach('my_secret',7102))
ptvsd.wait_for_attach()

如果你看到下面的网址

https://donjayamanne.github.io/pythonVSCodeDocs/docs/debugging_remote-debugging/

阅读以下报价

Make the above change in both script files (i.e. scripts on both the local and remote machines) However on the client side,ensure the above two lines are commented out I.e. this is necessary to ensure we have the same line numbers on the server and they match.

代码调试的执行都发生在容器内.虽然本地机器中的代码更能够可视化容器内代码的行

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读