You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

MacOS下PyCharm Docker Compose调试Django无法断点问题求助

Docker Compose Remote Python Debugger Stuck on "Waiting for Connection" in PyCharm (MacOS)

Yep, this is a super common issue a lot of us have run into when setting up remote debugging with Docker Compose and PyCharm on MacOS. The good news is there are several straightforward fixes to try—here's what worked for me and other developers:

  • Verify Port Mapping in docker-compose.yml
    Make sure you've mapped the debug port (default is 5678) from your host machine to the container. Add this line under your service's ports section:

    ports:
      - "5678:5678"
    

    Double-check that the port number matches what's set in your PyCharm debug configuration.

  • Ensure debugpy is Set Up Correctly in the Container

    • First, confirm debugpy is installed in your container—add it to your requirements.txt or install it via your Dockerfile with RUN pip install debugpy.
    • When launching your app in the container, use debugpy to start it with the right listen settings. Avoid using localhost here (it won't be accessible from your host); instead listen on all interfaces:
      python -m debugpy --listen 0.0.0.0:5678 --wait-for-client manage.py runserver
      

    The --wait-for-client flag ensures the app pauses until PyCharm connects, which helps avoid race conditions where the app starts before the debugger can attach.

  • Check PyCharm Debug Configuration Details

    • Open your Run/Debug Configurations, go to your remote debug entry, and confirm:
      • Host: Set to localhost (since we mapped the port to our host machine)
      • Port: Matches the one in your docker-compose.yml
      • Path Mappings: This is critical—map your local project root directory to the exact path where your code lives inside the container (e.g., /Users/yourname/your-project/app)
    • If you're still having issues, try enabling "Allow parallel run" in the configuration settings to avoid conflicts with existing debug sessions.
  • Rule Out MacOS Network/Firewall Blockages

    • Temporarily disable your Mac's firewall (System Settings → Network → Firewall) to see if that's blocking the connection. If it works after disabling, add an exception for PyCharm in the firewall settings.
    • In Docker Desktop, go to Settings → Resources → File Sharing and ensure "Allow the default Docker socket to be used" is enabled—this ensures proper network communication between PyCharm and the container.
  • Clear Caches and Restart Everything
    Sometimes stale Docker caches or PyCharm state can cause weird glitches:

    • Stop all running containers with docker-compose down
    • Clean up Docker's cached resources with docker system prune -af
    • Restart Docker Desktop and PyCharm, then rebuild and launch your containers again

If none of these steps resolve the issue, check PyCharm's debug logs (Help → Show Log in Finder) for more specific error messages—they often point to the root cause, like incorrect path mappings or port conflicts.

内容的提问来源于stack exchange,提问作者martin_crd

火山引擎 最新活动