Debugpy + Nvim-DAP in a Docker container - help getting this to work?

I’ve been trying to get Debugpy working with Nvim-DAP from inside a Docker container. I think I am close, but it’s not really working yet.

Here is my setup: GitHub - gwerbin/debugpy-in-docker at 0c0db5ff05d36b94ce1fb969e6b6a1295b26292c

I perform these steps:

  1. Open the runtime/service.py file in Neovim for editing.
  2. Run docker compose up --build to:
    2.1. Mount ./runtime as a “volume” in the container
    2.2. Start Debugpy, which starts Hypercorn, which starts the web server
    2.3. Expose the ports for Debugpy (9001) and the Uvicorn web server (8001) on my system
  3. Execute :lua require('dap').continue() to start a session, and select 1 for my “Generic remote” adapter.
  4. Open the Nvim-DAP REPL with :lua require('dap').repl.open().

It appears that Neovim is successfully starting a “session” that is connected to the Debugpy server inside the container. I can set breakpoints with :lua require('dap').toggle_breakpoint() and see the “B” sign appear in the sign column.

My Python program appears to run just fine. I can make requests with curl http://localhost:8001/, getting the correct responses and seeing the expected log output.

However I can’t seem to actually drop into the debugger at all, no matter if I set a breakpoint or I manually trigger an exception. Manually inserting a breakpoint() call just triggers a BdbQuit exception as you might expect.

Is there something I’m missing in the setup here?

Version info:

  • Neovim v0.5.0-dev+61aefaf29
  • Nvim-DAP at commit 7c6d12132339d7ef4136dabdd316a20e9c7dd8cf
  • Docker 20.10.5, build 55c4c88 with Docker Desktop for Mac
  • MacOS 10.14.6

Which python version is used in the Docker image? debugpy doesn’t work with python 3.9.3, see Break points are being ignored in Python 3.9.3 · Issue #587 · microsoft/debugpy · GitHub