user12314098
user12314098

Reputation:

VS code Python attach remote error 'connect ECONNREFUSED'

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

Upvotes: 7

Views: 12544

Answers (2)

Tamás Marics
Tamás Marics

Reputation: 9

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

sudo ufw allow <portNumber>

Upvotes: 0

Wason1797
Wason1797

Reputation: 216

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

Upvotes: 7

Related Questions