Django / Docker / Remote Debug using Pydev
<p>My setup is the following one :
- a django server running in a docker with port mapping: 8090:8090
- Eclipse with PyDev</p>

<p>I want to be able to put breakpoint on Pydev (click on a line, step by step)</p>

<p>I found several articles like;
<a href="http://www.pydev.org/manual_adv_remote_debugger.html" rel="nofollow noreferrer">http://www.pydev.org/manual_adv_remote_debugger.html</a></p>

<p>but it's still not working.</p>

<p>1) Should I update the manage.py to "import pydev" ? which lines to add and do I have to copy inside the docker container the pysrc of pydev plugin in order to be able to do the module import ? </p>

<p>2) Is there a port forwarding needed ? python instance running into docker should have access to remote debug server on host machine ?</p>

<p>3) I found article about pycharm and remote debug using ssh ? not possible to do similar with pydev ?</p>

<p>4) How to "link" my local directory and docker "directory" ?</p>

<p><strong>[EDIT] I found the solution</strong></p>

<ul>
<li><p>Copy the eclipse/path_to\pydev\plugins\org.python.pydev\pysrc directory into a place where your docker container can access it.</p></li>
<li><p>Edit pysrc/pydevd_file_utils.py, and add directory mapping between your host and docker container like:
PATHS_FROM_ECLIPSE_TO_PYTHON = [(r'C:/django',r'/.../lib/django'),
(r'C:/workspace/myapp',r'/var/www/myapp')]
you can set several tuples if you have several paths containing python code</p></li>
<li><p>edit manage.py and add the following </p>

<p>sys.path.append('/my_path/to_pysrc_/under_docker/pysrc')
import pydevd
pydevd.settrace(host='172.17.42.1') #IP of your host</p></li>
<li><p>In Pydev, in preferences > Pydev > Run/Debug  > Port for remote debugger: 5678</p></li>
<li><p>In Debug Perspective, click on "Start the Pydev server"</p></li>
<li><p>in your docker, run: python manage.py runserver 0.0.0.0:8090 --noreload</p>

<p>(replace 8090 by your http port) </p>

<ul>
<li><p>In Pydev: you will see that the code just break after settrace !</p></li>
<li><p>Now You can add some breakpoint and use the debug CLI of Pydev:) Enjoy !</p></li>
</ul></li>
</ul>