Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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


1 Answers

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

like image 134
Wason1797 Avatar answered Aug 05 '26 07:08

Wason1797



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!