1

I have a Django project that I can perfectly debug when ran on my machine through the CLI, however when I moved the logic into Docker & docker-compose, even though it runs without any issu I can no longer debug it, i.e. it does not stop at breakpoints, even though I can see through the debugger console that Pydevd receives commands related to addition / deletion of breakpoints:

/usr/local/bin/python3 /opt/.pycharm_helpers/pydev/pydevd.py --multiprocess --client host.docker.internal --port 55583 --file /opt/project/manage.py runserver 0.0.0.0:8000 
Container project-api-db-1  Running
Container project-api-project-api-1  Recreate
Container project-api-project-api-1  Recreated
Attaching to project-api-project-api-1
project-api-project-api-1  | Executing PyCharm's `sitecustomize`
project-api-project-api-1  | User doesn't have a custom `sitecustomize`
project-api-project-api-1  | Custom matplotlib backend was set for SciView
project-api-project-api-1  | Debugger warning: It seems that frozen modules are being used, which may
project-api-project-api-1  | make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
project-api-project-api-1  | to python to disable frozen modules.
project-api-project-api-1  | Note: Debugging will proceed.
project-api-project-api-1  | Unable to load jupyter_debug plugin
project-api-project-api-1  | Executing file /opt/project/manage.py
project-api-project-api-1  | arguments: ['/opt/project/manage.py', 'runserver', '0.0.0.0:8000']
project-api-project-api-1  | PYDEVD_FILTER_LIBRARIES False
project-api-project-api-1  | 
project-api-project-api-1  | ('Connecting to ', 'host.docker.internal', ':', '55583')
project-api-project-api-1  | ('Connected.',)
project-api-project-api-1  | debugger: received >>501   1   0.1 UNIX
project-api-project-api-1  | <<
project-api-project-api-1  | Received command: CMD_VERSION 501  1   0.1 UNIX
Connected to pydev debugger (build 231.9225.15)
project-api-project-api-1  | 
project-api-project-api-1  | sending cmd -->          CMD_VERSION @@BUILD_NUMBER@@
project-api-project-api-1  | debugger: received >>111   3   python-line /opt/project/screenshots/schemas/screenshot.py  37  mutate  THREAD  None    None
project-api-project-api-1  | 101    9   
project-api-project-api-1  | 146    11  SHOW_RETURN_VALUES  0
project-api-project-api-1  | 111    5   python-line /opt/project/screenshots/views.py   5   index   THREAD  None    None
project-api-project-api-1  | 111    7   python-line /opt/project/screenshots/schemas/screenshot.py  43  mutate  THREAD  None    None
project-api-project-api-1  | <<
project-api-project-api-1  | Received command: CMD_SET_BREAK 111    3   python-line /opt/project/screenshots/schemas/screenshot.py  37  mutate  THREAD  None    None
project-api-project-api-1  | 
project-api-project-api-1  | Added breakpoint:/opt/project/screenshots/schemas/screenshot.py - line:37 - func_name:b'mutate'
project-api-project-api-1  | 
project-api-project-api-1  | Received command: CMD_RUN 101  9   
project-api-project-api-1  | 
project-api-project-api-1  | Received command: CMD_SHOW_RETURN_VALUES 146   11  SHOW_RETURN_VALUES  0
project-api-project-api-1  | 
project-api-project-api-1  | Show return values: False
project-api-project-api-1  | 
project-api-project-api-1  | Received command: CMD_SET_BREAK 111    5   python-line /opt/project/screenshots/views.py   5   index   THREAD  None    None
project-api-project-api-1  | 
project-api-project-api-1  | Added breakpoint:/opt/project/screenshots/views.py - line:5 - func_name:b'index'
project-api-project-api-1  | 
project-api-project-api-1  | Received command: CMD_SET_BREAK 111    7   python-line /opt/project/screenshots/schemas/screenshot.py  43  mutate  THREAD  None    None
project-api-project-api-1  | 
project-api-project-api-1  | Added breakpoint:/opt/project/screenshots/schemas/screenshot.py - line:43 - func_name:b'mutate'
project-api-project-api-1  | 
project-api-project-api-1  | sending cmd -->    CMD_THREAD_CREATE <xml><thread name="MainThread" id="pid_1_id_281473140200016" /></xml>
project-api-project-api-1  | IDE_PROJECT_ROOTS ['/opt/project']
project-api-project-api-1  | 
project-api-project-api-1  | LIBRARY_ROOTS ['/Users/user/Library/Caches/JetBrains/PyCharm2023.1/remote_sources/-2013456723/-853142961', '/Users/user/Library/Caches/JetBrains/PyCharm2023.1/remote_sources/-2013456723/78907351', '/Users/user/Library/Caches/JetBrains/PyCharm2023.1/remote_sources/-2013456723/-727148301', '/Users/user/Library/Caches/JetBrains/PyCharm2023.1/python_stubs/1437855905', '/Applications/PyCharm.app/Contents/plugins/python/helpers/python-skeletons', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stdlib', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/gdb', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/six', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/boto', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/mock', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pytz', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/toml', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/tqdm', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/annoy', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/babel', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/emoji', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/first', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/fpdf2', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/ldap3', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/polib', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/redis', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/regex', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/retry', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/ujson', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/bleach', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/caldav', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/docopt', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/hdbcli', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/invoke', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/passpy', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Pillow', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/psutil', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pycurl', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pynput', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pysftp', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/PyYAML', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/stripe', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/xxhash', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/zxcvbn', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/appdirs', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/certifi', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/chardet', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/chevron', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/passlib', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyaudio', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/PyMySQL', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyvmomi', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/slumber', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/tzlocal', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/urllib3', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/vobject', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/aiofiles', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/colorama', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/croniter', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/docutils', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/html5lib', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/httplib2', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/jmespath', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Markdown', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/oauthlib', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/openpyxl', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/paramiko', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/psycopg2', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyflakes', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Pygments', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/requests', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/selenium', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/tabulate', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/toposort', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/waitress', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/braintree', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/decorator', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/freezegun', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/playsound', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyOpenSSL', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyRFC3339', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/termcolor', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/ttkthemes', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/typed-ast', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/xmltodict', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/cachetools', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/commonmark', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/dateparser', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Deprecated', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Flask-Cors', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/jsonschema', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pyfarmhash', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Send2Trash', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/setuptools', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/simplejson', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/SQLAlchemy', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/contextvars', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/entrypoints', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-2020', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/JACK-Client', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/mysqlclient', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/opentracing', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pep8-naming', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/prettytable', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/python-jose', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/python-nmap', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/stdlib-list', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/atomicwrites', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/aws-xray-sdk', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/cryptography', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/editdistance', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/parsimonious', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/whatthepatch', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/click-spinner', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/DateTimeRange', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/humanfriendly', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/python-gflags', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/beautifulsoup4', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-bugbear', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/python-slugify', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/singledispatch', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/dj-database-url', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-builtins', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-simplify', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/mypy-extensions', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/python-dateutil', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/Flask-SQLAlchemy', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-docstrings', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-plugin-utils', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/pytest-lazy-fixture', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-rst-docstrings', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/flake8-typing-imports', '/Applications/PyCharm.app/Contents/plugins/python/helpers/typeshed/stubs/backports.ssl_match_hostname']
project-api-project-api-1  | 
project-api-project-api-1  | Executing PyCharm's `sitecustomize`
project-api-project-api-1  | User doesn't have a custom `sitecustomize`
project-api-project-api-1  | Custom matplotlib backend was set for SciView
project-api-project-api-1  | Watching for file changes with StatReloader
project-api-project-api-1  | Performing system checks...
project-api-project-api-1  | 
project-api-project-api-1  | System check identified no issues (0 silenced).
project-api-project-api-1  | July 14, 2023 - 18:52:12
project-api-project-api-1  | Django version 4.2.3, using settings 'project_api.settings'
project-api-project-api-1  | Starting development server at http://0.0.0.0:8000/
project-api-project-api-1  | Quit the server with CONTROL-C.
project-api-project-api-1  | 
project-api-project-api-1  | [14/Jul/2023 18:52:15] "GET / HTTP/1.1" 200 13
project-api-project-api-1  | [14/Jul/2023 18:52:19] "GET / HTTP/1.1" 200 13

docker-compose.yml:

version: "3.7"
services:
  db:
    image: postgres:13.11-bullseye
    restart: always
    env_file:
      - database.env
    networks:
      - backend
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
  skreenshottr-api:
    tty: true
    stdin_open: true
    build:
      context: .
      dockerfile: .docker/Dockerfile
    command: python manage.py runserver 0.0.0.0:8000
    networks:
      - backend
    volumes:
      - .:/app
    ports:
      - "8000:8000"
    env_file:
      - .env
    depends_on:
      - db

networks:
  backend:
    name: backend
    external: true

volumes:
  postgres_data:
    driver: local

Here are my Python Interpreter configuration as well as my Django Server Run/Debug config: Python Interpreter configuration Django Server Run/Debug config

The code works like a charm, but never stops at breakpoints, even though when manually starting Django without using Docker, it stops at the breakpoints. Restarting PyCharm/Computer, updating PyCharm, deleting .idea folder or invalidating cache didn't work either.

EDIT:

  • PyCharm version: 2023.1.4
  • Pro Python version: 3.11.4
  • Docker version: 20.10.23
Prototype
  • 122
  • 1
  • 3
  • 12

1 Answers1

0

Docker recreates everything in its containers so you will not be able to access it with your standard debugging tools. It is possible to use pdb however to interactively debug. See this answer.

Akaisteph7
  • 5,034
  • 2
  • 20
  • 43