【问题标题】:Xdebug 3.0 WSL2 and VSCode - address is already in use by docker-proxyXdebug 3.0 WSL2 和 VSCode - 地址已被 docker-proxy 使用
【发布时间】:2022-07-12 00:00:58
【问题描述】:

我在 WSL 中的 VSCode:Ubuntu 无法监听 xdebug 端口,因为它被某些 docker-proxy 阻止了。

我在关注这个Solution,但是尝试 VSCode 监听 xdebug 端口,导致以下错误:

错误:监听 EADDRINUSE:地址已在使用 :::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: 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 我试过了:

comment 中那样从 Dockerfile/docker-compose 中删除 Expose 指令也不会删除错误。

【问题讨论】:

  • xdebug://gatewayxdebug://nameserver 还没有发布版本,所以它们不能工作:-)
  • 1) 重新启动 PC,可能会有所帮助 2) 仔细检查任何活动/正在运行的 Docker 映像都没有任何服务使用或公开的 9003 端口。 3) 当你运行零个 Docker 镜像时,一个接一个地关闭镜像——它还在吗? 4) 关闭 Docker——它还在吗? 4) 在 php.ini 和 VSCode ofc 中使用另一个 Xdebug 端口(例如 9004 或其他数字)。
  • 感谢您的帮助。我删除了 9003 的所有暴露,并且 php-fpm-container 是唯一具有端口绑定 9003:9003 的容器。如果我从 docker-compose.yml 中删除它,则端口可以免费收听。但是,即使我使用 ubuntu 的 /etc/resolv.conf 中的 ip 配置 xdebug.client_host,VSCode 仍然没有捕获调试会话。

标签: docker visual-studio-code windows-subsystem-for-linux xdebug wsl-2


【解决方案1】:

解决了。对于有此挑战的其他人:

wsl-ubuntu 内部 -> docker-containter host.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} ...

【讨论】:

  • 在 Xdebug 3.2 及更高版本(尚未发布)中,您可以使用xdebug.client_host=xdebug://nameserver 自动执行此操作。
猜你喜欢
  • 2021-05-17
  • 2018-11-30
  • 1970-01-01
  • 2020-03-23
  • 2020-09-13
  • 2021-09-24
  • 2021-12-02
  • 1970-01-01
  • 2017-09-07
相关资源
最近更新 更多