AlxVallejo
AlxVallejo

Reputation: 3219

Debugpy won't attach to anything

I've tried everything except what works. Nothing gets my vscode debugger to attach to any breakpoint.

Here is my launch.json:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [ 
    {
      "name": "Python: Docker",
      "type": "python",
      "request": "attach",
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "/code"
        }
      ],
      "connect": {
        "host": "localhost",
        "port": 3000
      },
      "justMyCode": true,
      "logToFile": true
    }
}

And here is my docker-compose.yml:

services:
  web:
    platform: linux/amd64
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - 8800:8000
      - 3000:3000

And in my manage.py:


if settings.DEBUG:
if os.environ.get('RUN_MAIN') or os.environ.get('WERKZEUG_RUN_MAIN'):
    import debugpy
    debugpy.listen(("0.0.0.0", 3000))
    # debugpy.wait_for_client()
    print('debugpy Attached!')

My debugpy Attached! is being printed so I know things are set up to be attached to the debugger, but none of my breakpoints work.

Also, i'd like to add that i'm testing a Django management command:

python manage.py myCommand

I'm assuming that no additional configuration is needed if i'm running a command within the container. It will use the server that is running and debugpy should be loaded. I've tried specifying debugpy in the command itself but still nothing:

python -m debugpy --listen 0.0.0.0:3000 manage.py myCommand

Upvotes: 0

Views: 1045

Answers (1)

AlxVallejo
AlxVallejo

Reputation: 3219

Well, I'm stupid.

Not only do you need to open the port in docker-compose.yml but also the Dockerfile that's running Django under the docker-compose. Makes perfect sense now.

Upvotes: 0

Related Questions