Debug inside Docker
Hi,
I got my project running in Docker and now I would like to use it also for debugging.
I was able to create a run configuration in PyCharm but the debug option fails for me and I don't really understand why. I googled around and it seems that there is another way using the Python Remote Debug option from the Run/Debug configuration window. And now here comes the thing I don't get.
Quoting from the help page
```
In order to debug with a remote interpreter, you have to start your program through PyCharm, which is not always possible. On the other hand, when using the Debug Server, you can connect to a running process.
```
If I understand this right it should mean that if I'm able to start my code with PyCharm inside a docker container (note that I'm really using a run configuration and not CMD inside Docker) it should also work for the Debug configuration. But the result is this error message:
```
9c7759ff5934:python -u /opt/.pycharm_helpers/pydev/pydevd.py --multiprocess --qt-support=auto --port 59431 --file /usr/local/bin/twistd --umask 0022 --nodaemon --pidfile= -l - cowrie
Unsupported setsockopt level=1 optname=15
Could not connect to None: 59431
Traceback (most recent call last):
File "/opt/.pycharm_helpers/pydev/pydevd.py", line 1649, in main
debugger.connect(host, port)
File "/opt/.pycharm_helpers/pydev/pydevd.py", line 326, in connect
s = start_server(port)
File "/opt/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 510, in start_server
s.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1)
File "/usr/local/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
error: [Errno 92] Protocol not available
Process finished with exit code 1
```
OS: macOS High Sierra
PyCharm Professional 2018.2
Cheers
Please sign in to leave a comment.
Hi crane
> If I understand this right it should mean that if I'm able to start my code with PyCharm inside a docker container ... it should also work for the Debug configuration
It is correct.
> error: [Errno 92] Protocol not available
Hm, that's odd, is it possible for you to share the Dockerfile? Please feel free to create a ticket in our bug tracker and attach it there directly.
Thx for the reply.
I opened a bug report for this issue and attached my Dockerfile.
https://youtrack.jetbrains.com/issue/PY-31652
Another problem:
PyCharm will fail to debug any Docker container that has more then just one python file.
Simple repo: add one line to python main.py file.
import anotherFile
PyCharm will throw "remote file can't be found" with three non-working options.
Both PyCharm 2018 and 2019.
@Roman
Are you sure that the second file was uploaded into container? Does the code run in non-debug mode without exceptions?