【问题标题】:How can I debug php mounted to a container running on docker beta for mac如何调试安装到在 docker beta for mac 上运行的容器的 php
【发布时间】:2016-07-07 18:37:44
【问题描述】:

我花了半天时间尝试不同的东西,包括我在gist.github.com 遇到的这个解决方案

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

 volumes:
    - ~/projectx:/projectx

我的 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 访问我的 web 应用程序(和其他 docker web 应用程序),所有这些都可以运行应用程序

在 Phpstorm(2016.1.2 版)中,在首选项中 -> Languages & Frameworks -> PHP -> 我拥有的服务器:

host = dtest.xxx.com, port=80 , Debugger = Xdebug
勾选使用路径映射,我有
文件/目录设置为/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)

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

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

【问题讨论】:

    标签: php docker xdebug


    【解决方案1】:

    更新 2:

    正如@Rashidul 所指出的,从17.06 docker for 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 隧道

    原解决方案:

    我使用的解决方法是使用类似命令打开到运行 php 的 docker 容器的 ssh 隧道,在我的情况下,我将 docker 容器 ssh 端口映射到 12,因此 -p 12

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

    【讨论】:

    • 那还需要ssh隧道吗?
    • @Pilippe 不,它不需要 ssh 隧道
    • @jonnie 您展示的主机 IP 所在位置的事实解决了我在 docker beta 容器中设置 zend 调试器时遇到的问题。谢谢!
    • 这也适用于 Windows!除此之外,您还可以通过打开 windows cmd 并输入 ipconfig(网络适配器的 IPv4 地址)来获取远程主机 IP。我不知道[...]/slirp/host在Windows上的位置。
    • @jonnie,从 17.06 docker for mac 开始,你可以用xdebug.remote_host="docker.for.mac.localhost"替换xdebug.remote_host="192.168.65.1"
    猜你喜欢
    • 2020-03-01
    • 1970-01-01
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多