vscode python 远程调试,Visual Studio Code-如何在Docker容器中远程调试python代码

博客内容描述了在Visual Studio Code(VSC)中尝试远程调试运行在Docker容器内的Python应用遇到的问题。作者配置了Dockerfile、debug.py和launch.json文件,但调试时没有输出和错误。解决方案指出应使用ptvsd的3.0.0版本,并更新Dockerfile及本地安装。
摘要由CSDN通过智能技术生成

Iam trying to remote dubug python in VSC:

It is main.py file:

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"]

and it is launch.json file:

{

"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"

}

]

}

It is a command to build and start container:

docker build -t python-for-debug .

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

When I run the debugger I get:

screen of vs code

No any errors at debug console, not output, not problems. No any output for running container. No docker logs

VS Code version: 1.15.0

Docker version 17.06.0-ce, build 02c1d87

解决方案

Hi you should use ptvsd 3, so change the RUN line in Dockerfile to:

RUN pip3 install ptvsd==3.0.0

also run locally ptvsd installation:

$pip3 install ptvsd==3.0.0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值