python - VS 代码 Python 附加远程错误 'connect ECONNREFUSED'

标签 python django docker visual-studio-code ptvs

所以我在 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" ]

这是我的 docker-compose
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 ECONNREFUSE 192.168.99.100:3500”。有什么建议?

我正在遵循本指南:
https://www.youtube.com/watch?v=b78Tg-YmJZI

最佳答案

我也有这个问题。我找到了解决方案 here
基本上,您必须使用 debugpy.listen(("0.0.0.0", 5678)) 配置调试器
发生这种情况是因为默认情况下 debugpy 正在监听 localhost。如果你在另一台主机上有你的 docker 容器,你必须添加 0.0.0.0

关于python - VS 代码 Python 附加远程错误 'connect ECONNREFUSED',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61204424/

相关文章:

Python bs4 : How to Repeat “For” Loop with a Different Scraped Page if a Certain Condition is Met?

python - 如何在全屏模式下更改 Gtk 应用程序的布局?

django - 根据与登录用户的关系限制表单选项

python - Heroku 和 Amazon S3 上的 Django 压缩器错误 "UncompressableFileError"

套接字中的 Java 客户端

python - 数据帧 : add column whose values are the quantile number/rank of an existing column?

用于不同环境(如开发、生产或暂存)的 Python 基础部署技术/包库

docker - 如何通过 yaml list 挂载 docker 容器的卷?

java - 无法使用 Java API 连接到在本地虚拟机上运行的 ElasticSearch Docker 集群

node.js - 准备失败 : Cannot connect to the Docker daemon at unix:///var/run/docker. sock