php - Xdebug 无法连接回 Docker 主机

标签 php docker xdebug 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

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

在本地机器上,我可以远程登录到端口 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.

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

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

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

任何关于为什么这行不通的见解都将受到极大欢迎。提前致谢。

最佳答案

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

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

I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST ?
The Mac has a changing IP address (or none if you have no network access). From 17.06 onwards our recommendation is to connect to the special Mac-only DNS name docker.for.mac.localhost which resolves to the internal IP address used by the host.

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

关于php - Xdebug 无法连接回 Docker 主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38192502/

相关文章:

php - 如何对包含的文件(例如 .css)使用相对路径

php - 在本地主机中工作时是否可以连接到远程数据库?

php - 无法删除字符串中的空格

docker - Kubernetes 描述 pod - 来自服务器的错误 (NotFound)

php - 从 PHPUnit 代码覆盖率中排除基本目录

PHP - 魔法引用 gpc 和 stripslashes 问题

docker - 安装 Couchbase 的特定 docker 镜像

linux - nginx docker,如何更改公共(public)路径?

php - Docker + Xdebug + VSCode 无法连接到客户端

laravel - 如何使用 Laradock 和 PhpStorm 配置 Xdebug