docker 主机 (OSX) 上的关闭端口在内部 docker 网络上保持/报告打开状态

gkr*_*4kg 5 port networking docker macos-monterey

在 OSX 12.3 上将 Docker 升级到 4.6.0 后,当我停止 PHPStorm 中的 xdebug 监听客户端时,我遇到了一些奇怪的问题,似乎后续请求总是超时,因为 docker 报告 host.docker.internal 有端口9003 在实际关闭时打开,因此应用程序始终等待 xdebug 客户端。

我在我的 webapp php 容器和主机上安装了 nmap 进行测试。如果我在主机上运行调试客户端时运行“nmap -p 9003 localhost”,我可以看到它打开,在 PHPstorm 中将其关闭后,相同的扫描显示它已关闭,但是运行“nmap -p 9003 host.docker.internal”容器内部报告其仍处于打开状态。如果我也在主机上打开其他服务,似乎端口开始在 docker 内部网络上显示为打开状态,但在主机上关闭它们后永远不会报告为关闭。

我升级到 Docker 4.6.1 但问题仍然存在。

任何意见,将不胜感激。

Vip*_*ret 1

UPDATE: Downgrading to Docker 4.5.0 resolved the issue.

This doesn't solve the problem, just helps to avoid restarting Docker while we are waiting for the fix. Make changes in xdebug.ini:

xdebug.start_with_request=trigger
xdebug.idekey=VSCODE
Run Code Online (Sandbox Code Playgroud)

This tells XDebug to connect to debugger only if "trigger" is present in the HTTP request.

Now, install Chrome extension Xdebug helper, it's old but still works. Open extensions settings (chrome-extension://eadndfjplgieldjbigjakmdgkmoaaaoc/options.html) and set IDE key to "Other" "VSCODE".

Xdebug 帮助程序设置

Now, when you want to debug, you enable debugging in VSCode and also enable debugging in Chrome using that extension:

在 Xdebug 帮助程序中启用调试

When you are done debugging - choose "Disable" in the extension, and PHP won't try to connect to your debugger, even if the port is still open. How it works - extension just sends cookie XDEBUG_SESSION=VSCODE with each request, and XDebug connects to the debugger only when this cookie is present.

P.S. You can replace VSCODE with IDE key that your IDE uses, or just any string.