Xdebug 无法连接回 Docker 主机

Tob*_*byG 7 php xdebug docker boot2docker docker-machine

我刚刚在我的机器上设置了 Docker 并且有一个 Nginx/PHP7 (FPM)/MySQL 设置一切正常,但是在 PHP 容器上安装了 Xdebug 我无法让它连接回我主机上的 PHPStorm。

这是我的 PHP Xdebug 配置...

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-
20151012/xdebug.so
xdebug.remote_log=/usr/local/var/log/xdebug.log
xdebug.remote_enable=1
xdebug.remote_host=192.168.99.1
xdebug.remote_port=9000
xdebug.remote_connect_back=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true
Run Code Online (Sandbox Code Playgroud)

浏览时,如果为容器设置了 Xdebug 启用 cookie,则不会提示连接。如果我浏览一个本地托管的站点,那么我知道 PHPStorm 的收听是正确的。

在本地机器上,我可以 telnet 到端口 9000...

$ telnet 192.168.99.1 9000
Trying 192.168.99.1...
Connected to 192.168.99.1.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
Run Code Online (Sandbox Code Playgroud)

...但是我不能从 boot2docker VM 或容器。当我尝试时,它只是坐在那里什么都不做。然而,VM 和容器都可以很好地 ping 主机。

我试过禁用我的 Mac 的防火墙,但仍然没有乐趣。

我不太确定如何禁用 boot2docker VM 上的防火墙。

任何有关为什么这不起作用的见解都将受到极大欢迎。提前致谢。

lyf*_*ing 10

Xdebug 推荐的容器内配置:

zend_extension = xdebug.so
xdebug.remote_enable = 1
xdebug.remote_connect_back = 0
xdebug.remote_host = docker.for.mac.localhost
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.remote_mode = req
xdebug.remote_autostart = 1
xdebug.idekey = PHPSTORM
Run Code Online (Sandbox Code Playgroud)

从 Docker-17.06 开始,您可以通过静态主机名访问 Container 内托管在 Mac 上的服务: docker.for.mac.localhost

我想从容器连接到主机上的服务?
Mac 有一个不断变化的 IP 地址(如果您没有网络访问权限,则没有)。从 17.06 开始,我们的建议是连接到特殊的 Mac 专用 DNS 名称 docker.for.mac.localhost,该名称解析为主机使用的内部 IP 地址。

https://docs.docker.com/docker-for-mac/networking/#i-cannot-ping-my-containers

  • `xdebug.remote_host = host.docker.internal` 自 Docker 版本 18.03.0-ce-mac59, 2018-03-26 开始工作 (3认同)