我如何在 docker beta 上调试 php 安装到容器 运行 的 mac

How can I debug php mounted to a container running on docker beta for mac

我花了半天时间尝试不同的事情,包括我在 gist.github.com

上遇到的这个解决方案

我有一个 docker-compose 文件,它安装了一个包含我的客户端和服务器项目的文件夹:

 volumes:
    - ~/projectx:/projectx

my docker php.ini 包含以下 xdebug 选项

[xdebug]
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_connect_back=On
xdebug.var_display_max_children = 999
xdebug.var_display_max_data = 999
xdebug.var_display_max_depth = 100

我安装了 xdebug chrome extension

在我的 mac 主机文件中,我有以下内容 127.0.0.1 localhost dtest.xxx.com,因此我可以通过 dtest.xxx.com 访问我的网络应用程序(和其他 docker 网络应用程序),一切正常运行 应用

在 Phpstorm(版本 2016.1.2)中 在首选项中 -> 语言和框架 -> PHP -> 我拥有的服务器:

host = dtest.xxx.com, port=80 , Debugger = Xdebug
Use path mappings 已选中,我有
File/Directory 设置为 /Users/<myname>/projectx/server
服务器上的绝对路径设置为 /projectx/server

我已经尝试将 xdebug.remote_host 设置为我从 ifconfig 获得的 macs ip 以及尝试 /Users/<myname>/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/slirp/host

中的 ip

但是我不能打断点,我什至添加了 xdebug_break() 双重检查。 我也在 运行 最新的 docker beta Version 1.12.0-rc3-beta18 (build: 9996)

我非常感谢任何人的帮助,这对我来说是一个真正的阻碍。

如果需要任何进一步的信息,我很乐意提供。

更新 2:

正如@Rashidul 所指出的,从 17.06 docker 开始 Mac,您可以将 xdebug.remote_host="192.168.65.1" 替换为 xdebug.remote_host="docker.for.mac.localhost"

更新:正确的方法

所以我最终发现我在 docker 中的 xdebug 设置应该是

xdebug.enable=1
xdebug.remote_enable = 1
xdebug.idekey="PHPSTORM"
xdebug.remote_port=9000
xdebug.remote_host="192.168.65.1"
xdebug.remote_connect_back=0

其中 192.168.65.1 是在 ~/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/slirp/host

中找到的条目

在最近的更新中,以上不再存在,要获取我知道的 Docker 主机 IP,请使用下面的 .profile

export DOCKER_HOST_IP=$(ipconfig getifaddr en0)

还要确保在 chrome 扩展中正确设置了 idekey,在我的例子中 PHPSTORM
有了这个,我不再需要 ssh 隧道

原解:

我使用的解决方法是打开一个通向 docker 容器 运行 php 的 ssh 隧道,使用如下命令,在我的例子中,我有 docker容器 ssh 端口映射到 12 因此 -p 12

ssh -R 9000:localhost:9000 root@dtest.xxx.com -p:12