Search code examples
pythondjangodockerpycharmremote-debugging

Pycharm debugging manage.py commands in docker compose


I have a pretty simple setup. I'm running Pycharm 2018.2.3 and using docker compose to spin up 3 containers.

  1. My Django application
  2. NGINX to serve static
  3. Postgres DB

I've configured the remote interpreter for debugging the container, and break point work just fine in most cases, at least when I hit my API endpoints or some other action to the django application.

What does not work, is when I run one of my manage custom manage.py custom commands. I've tried this 2 ways so far.

  1. I setup another debug configuration in PyCharm to execute the command. This results in another container spinning up (in place of the original. Running the command, without breaking on any line breaks. Then the whole container shuts down.

  2. I've logged into the container, run the manage.py command directly via the command line, and it execute in the container, but again no breakpoints.

The documentation seems to work in the normal case, but I can't find any help for debugging these commands in the container.

Thanks for any help or tips.


Solution

  • Just an update in case anybody comes across a similar problem. My personal solution was to not use the manage.py commands, but instead make these same commands available via an http call.

    I found that it was easier (and often even more useful) to simply have an endpoint like myserver.com/api/do-admin-function and restrict that to administrative access.

    When I put a breakpoint in my code, even running in the container, it breaks just fine as expected and allows me to debug the way I'd like