VS代码Python附加远程错误“connect Econrefused”

2024-05-20 21:28:40 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我在Docker内部运行了这个Django应用程序,我正在尝试将VS代码附加到它,以便调试。这是我的启动文件

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "port": 8800,
            "host": "192.168.99.100",
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ]
        }
    ]
}

这是我的docker文件

FROM registry.gitlab.com/datadrivendiscovery/images/primitives:ubuntu-bionic-python36-v2020.1.9

ENV PYTHONUNBUFFERED 1

RUN mkdir /bbml

WORKDIR /bbml
COPY requirements.txt /bbml/
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN pip install ptvsd
ADD . /bbml/

CMD python -m ptvsd --host 0.0.0.0 --port 3500 --wait --multiprocess -m ./manage.py runserver 0.0.0.0:8800
# CMD [ "python", "./manage.py runserver 0.0.0.0:8800" ]

这是我的码头工人

version: '3'

services:
  web:
    build: .
    command: "python3 manage.py runserver 0.0.0.0:8800"
    container_name: bbml
    volumes:
      - .:/bbml
    ports:
      - "8800:8800"
      - "3500:3500"

正如您所看到的,我正在端口3500上运行ptvsd,但每次我按下VScode上的绿色运行按钮时,我都会得到“connect ECONREFUSE 192.168.99.100:3500”。有什么建议吗

我遵循这个指南: https://www.youtube.com/watch?v=b78Tg-YmJZI


Tags: installpip文件torunnamepyhttps
1条回答
网友
1楼 · 发布于 2024-05-20 21:28:40

我也有这个问题。我找到了解决办法here

基本上,您必须使用debugpy.listen(("0.0.0.0", 5678))配置调试器

这是因为默认情况下,debugpy正在本地主机上侦听。如果您的docker容器位于另一台主机上,则必须添加0.0.0.0

相关问题 更多 >