Ubuntu - Docker Compose Debug Connection Refused

I'm on a fresh install of Ubuntu 22.04.3 LTS  and PyCharm 2023.3.2 (Professional Edition).

I know this has been discussed at great length for other OS, but I'm having an issue debugging in Ubuntu when using remote (docker-compose) interpreter. I've successfully debugged a remote docker (w/ docker compose) on my Mac, but I get the following error when I try to debug (run works fine):

/usr/local/bin/python3 /opt/.pycharm_helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 172.17.0.1 --port 41781 --file /opt/project/kamsa_api/manage.py runserver 0.0.0.0:8000 

Container redis  Running
Container es  Running
Container django_web  Recreate
Attaching to django_web
Container django_web  Recreated

django_web  | warning: PYDEVD_USE_CYTHON environment variable is set to 'NO'. Frame evaluator will be also disabled because it requires Cython extensions to be enabled in order to operate correctly.

django_web  | Could not connect to 172.17.0.1: 41781
django_web  | Traceback (most recent call last):
django_web  |   File "/opt/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 463, in start_client
django_web  |     s.connect((host, port))
django_web  | ConnectionRefusedError: [Errno 111] Connection refused
django_web  | Could not connect to 172.17.0.1: 41781
django_web  | Traceback (most recent call last):
django_web  |   File "/opt/.pycharm_helpers/pydev/pydevd.py", line 2206, in main
django_web  |     debugger.connect(host, port)
django_web  |   File "/opt/.pycharm_helpers/pydev/pydevd.py", line 670, in connect
django_web  |     s = start_client(host, port)
django_web  |   File "/opt/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 463, in start_client
django_web  |     s.connect((host, port))
django_web  | ConnectionRefusedError: [Errno 111] Connection refused

Aborting on container exit...
Container django_web  Stopping
Container django_web  Stopped

django_web exited with code 1

 

I have verified I do not have any firewall issues, docker is running, etc. I cannot use network mode host as I need specific ports to reach other running containers. I have also tried to use the docker.sock as a TCP connection, as well.

When comparing the set up to my Mac, everything is basically identical. I've tried a number of solutions found on this forum, but nothing seems to work. 

I suspect the issue is the fact that it's identifying the --client as 172.17.0.1. My Mac uses host.docker.internal for this, but I can't seem to figure out how to switch this. Custom run command doesn't allow me to change. 

Additionally, I cannot open the Python Console window either. I get the following issue. I suspect it is the same issue with the --host=172.17.0.1

/usr/local/bin/python3 /opt/.pycharm_helpers/pydev/pydevconsole.py --mode=client --host=172.17.0.1 --port=39883 
Traceback (most recent call last):
  File "/opt/.pycharm_helpers/pydev/pydevconsole.py", line 570, in <module>
    pydevconsole.start_client(host, port)
  File "/opt/.pycharm_helpers/pydev/pydevconsole.py", line 482, in start_client
    client, server_transport = make_rpc_client(client_service, host, port)
  File "/opt/.pycharm_helpers/pydev/_pydev_comm/pydev_rpc.py", line 11, in make_rpc_client
    client_transport, server_transport = open_transports_as_client((host, port))
  File "/opt/.pycharm_helpers/pydev/_pydev_comm/pydev_transport.py", line 231, in open_transports_as_client
    client_socket.connect(addr)
ConnectionRefusedError: [Errno 111] Connection refused
Couldn't connect to console process.
Process finished with exit code 1

Any help would be much appreciated.

 

2
4 comments

So I have figured out at least the core part of this. 

It's because, in Linux, PyCharm needs root privileges to tell the OS it wants to listen to the debug port. Starting PyCharm with sudo is possible, though it's a pain, and it caused some other issues with Docker then needing to be run with sudo, which causes other issues.

I'm working through them, but it was be easier if there was a way for PyCharm to ask for sudo just for the task of listening on those ports.

0

Matt Harbers did you manage to resolve the issue?

0

I did not find a consistent solution. I was able to eventually run the one container with root Pycharm, but even after that it would inexplicably stop pausing on breakpoints. Nothing would change, it would just stop. You'd come back a few hours later, and it would work again. I've gone back to just using native debugging for my main package. It seems entirely a PyCharm issue based on the other forum posts I've seen about it

0

Thanks for replying, Matt Harbers! Let's hope it will get a fix soon :) 

0

Please sign in to leave a comment.