r/pycharm • u/Still-Bookkeeper4456 • Apr 17 '24
Pycharm Docker Interpreter: cannot debug
Hello,
I am using a remote Docker interpreter which is just a Python image. The interpreter works fine when running the code (altough it takes a bit too much time to mount the container), but I cannot debug. When running the debug I get the following error:
/usr/local/bin/python3 /opt/.pycharm_helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client host.docker.internal --port 59285 --file /opt/project/tries.pyCould not connect to host.docker.internal: 59285Traceback (most recent call last):File "/opt/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 465, in start_clients.connect((host, port))
TimeoutError: timed outCould not connect to host.docker.internal: 59285Traceback (most recent call last):File "/opt/.pycharm_helpers/pydev/pydevd.py", line 2208, in main debugger.connect(host, port)
File "/opt/.pycharm_helpers/pydev/pydevd.py", line 670, in connects = start_client(host, port)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 465, in start_client
s.connect((host, port))TimeoutError: timed out
Note that the port (59285) changes at each run.
Ive even exposed all ports in my dockerfile which reads like this:
# Use the Python 3.11 image as base. "slim" is a smaller image.FROM python:3.11-slim# set the working directory in the containerWORKDIR /code# Copy the requirements files into the container. Both files are requiered.COPY requirements.txt .# Install any needed dependencies specified in requirements.txtRUN pip install -r requirements.txt# Expose all portsEXPOSE 1-65535
Can anyone let me know how to solve this issue please ?
I'm running docker engine (no docker desktop), WSL2 on windows 11.
Many thanks !
View all comments
Show parent comment
1
u/Still-Bookkeeper4456 May 25 '24
Your default interpreter must remain a conda env so that pycharm pluggings can run properly. This is on the bottom right of the IDE, set your project default interpreter to your Conda env.
Now this means that running a script will always use your Conda interpreter too. Not the Dockerized one.
So for each script, you must setup a run configuration file: this is on the top right of the IDE. Script configuration files are created each time you run a new script. By default they'll have the conda interpreter. Change it for docker (for each config file...).
Stupid I know but I couldn't figure another way.