VS code Python attach remote error 'connect ECONNREFUSED'
Asked Answered
C

2

6

So I have this Django app inside of Docker running and I'm trying to attach VS code to it so I can debug here is my launch file

{
    // 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": "."
                }
            ]
        }
    ]
}

Here's my docker file

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

here's my 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"

As you can see I'm running ptvsd on port 3500, but everytime I push the green run button on VScode I get "connect ECONNREFUSE 192.168.99.100:3500". Any suggestions?

I was following this guide: https://www.youtube.com/watch?v=b78Tg-YmJZI

Chancellorsville answered 14/4, 2020 at 9:22 Comment(3)
You don't want ptvsd, you want debugpy.Harry
@BrettCannon why's that?Chancellorsville
Because ptvsd is no longer supported and debugpy is the new debugger.Harry
C
5

I also had this problem. I found the solution here

basically, you have to configure the debugger with debugpy.listen(("0.0.0.0", 5678))

This happens because by default debugpy is listening on localhost. if you have your docker container on another host you have to add 0.0.0.0

Corry answered 4/11, 2020 at 20:40 Comment(1)
Note the tuple, double parentheses, and NOT two parameters. Ignoring this will also throw a connection refused error.Borrell
T
0

For me it was that the port I tried to use wasn't open on the remote machine:

sudo ufw allow <portNumber>
Tourcoing answered 18/5, 2022 at 9:18 Comment(2)
This helped slove the problem. Thanks!Aguish
What if ufw is not there in a docker container? Where else could this be blocking me?Berth

© 2022 - 2025 — McMap. All rights reserved.