我在 WSL:Ubuntu 中的 VSCode 無法監聽 xdebug 埠,因為它被一些 docker-proxy 阻止。我正在關注此解決方案,但嘗試 VSCode 偵聽 xdebug 埠,導致以下錯誤:
Error: listen EADDRINUSE: address already in use :::9003
任何人都可以幫助將 VSCode 連接到 xdebug 嗎?
Windows 11 表示該埠已由 wslhost 分配:
PS C:\WINDOWS\system32> Get-Process -Id (Get-NetTCPConnection -LocalPort 9003).OwningProcess
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
285 47 2288 4748 0,05 19480 1 wslhost
Ubuntu 告訴它,它是由一些 docker-proxy 分配的:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9003 0.0.0.0:* LISTEN 17210/docker-proxy
tcp6 0 0 :::9003 :::* LISTEN 17217/docker-proxy
碼頭工人撰寫版本:docker-compose version 1.25.0
xdebug.log 說:
[Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003.
[Step Debug] ERR: Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(
舒爾,只要沒有人在聽。
至于xdebug.client_host我試過:
- 主機.docker.internal
- xdebug://gateway和xdebug://nameserver指的是這個:https ://docs.google.com/document/d/1W-NzNtExf5C4eOu3rRQm1WlWnbW44u3ANDDA49d3FD4/edit?pli=1
- 使用 docker-compose.yml 設定環境變數:
XDEBUG_CONFIG="client_host=..."
從 Dockerfile/docker-compose 中洗掉 Expose 指令,如本評論所示,也不會洗掉錯誤。
uj5u.com熱心網友回復:
解決了。對于其他面臨這一挑戰的人:
wsl-ubuntu 內部 -> docker-containterhost.docker.internal指向錯誤的 ip。在 wsl-distribution 中,該檔案/etc/resolv.conf是 windows 主機的 ip。要獲得正確的 ip,請使用以下答案:How to get the primary IP address of the local machine on Linux and OS X?
我的解決方案是用這個 ip 定義一個環境變數:
alias docker_compose_local_ip="ifconfig eth0 | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'"
export DOCKER_COMPOSE_LOCAL_IP=$(docker_compose_local_ip)
并用它配置容器:
services:
service-name:
environment:
- XDEBUG_CONFIG=client_host=${DOCKER_COMPOSE_LOCAL_IP} ...
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/480902.html
標籤:码头工人 视觉工作室代码 windows-subsystem-for-linux xdebug wsl-2
