Xdebug Docker 跨容器通信设置

Xdebug Docker Cross Container Communication setup

我遇到多容器/跨容器 Xdebug PhpStorm 通信问题。

我有一个包含 10 个容器的设置,它们相互通信,但似乎无法让 Xdebug 在所有容器中工作。

举个例子: 容器 A 向容器 B 发出请求,容器 B 向容器 C 发出请求。 如何让断点在 Container B 和 C 处停止?

目前我遇到超时,没有 Xdebug,他们的通信没有问题。

作为旁注,跨容器通信正在工作,它们在同一个网络中,Xdebug 在每个容器上独立工作。

这是我所有容器中的 Xdebug 配置:

xdebug.remote_port=9006
xdebug.remote_autostart=1
xdebug.remote_enable=1  
xdebug.remote_connect_back=0 
xdebug.remote_host=10.254.254.254 
xdebug.idekey=PHPSTORM

找到解决方案,

在进一步挖掘相关的 github 问题后,我发现了这个话题: https://github.com/docksal/docksal/issues/389 这个计算器问题: Docker / Xdebug Over LAN Server Multiple Developers

这让我尝试了这个工作配置:

所有容器中的最终配置现在是:

xdebug.remote_port=[PORT]
xdebug.remote_autostart=1
xdebug.remote_enable=1  
xdebug.remote_connect_back=0 
xdebug.remote_host=10.254.254.254 
xdebug.idekey=PHPSTORM

提示:每个容器必须有不同的端口!

例如

  1. 服务 1 = 9006
  2. 服务 2 = 9007
  3. 服务 3 = 9008

等等

基本上使用 docker 内部网络并使用 remote connect back 解决了它。