php – Docker和XDebug没有读取断点VSCode

在过去的6个月中,我一直在使用XDebug和PHP Version 7.0.*在远程调试Docker容器的MAC上.

我正在运行一个旧版本的docker,它使用VirtualBox到VM for docker,一切正常.

我最近更新了docker到版本17.03.1并且除了xDebug之外什么都没有.我通过他的存储库上的一个问题联系了vscode-PHP-debug的创建者,然后他指出我用xdebug和/或docker来解决这个问题.

我的问题如下:

XDebug正在运行并处理我的容器,xdebug日志显示它连接到我的IDE,但它只是关闭连接,就像我在VSCode中设置了断点时没有断点一样.

我在vscode-PHP-debug上发布的问题可以在here找到

其中包含我的xDebug日志和VSCode调试日志的副本…它显示已建立连接但未命中断点.

我已经阅读了几篇博客,其中docker现在需要为连接到xdebug而创建的环回ip才能工作,我也试过并失败了.

我发现使用一个这么长时间后没有调试器就很难调试.

我尝试了许多配置,重新安装,重新启动,重建图像/容器,甚至尝试了freenode上的docker和xdebug irc通道而没有任何成功.

解决方法:

EDIT-2 2018

现在可以更改remote_host值以支持所有平台:

xdebug.remote_host = "host.docker.internal"

EDIT-1 2018
不再需要使用plist修复.正如在这个要点:https://gist.github.com/chadrien/c90927ec2d160ffea9c4#gistcomment-2398281中指出的,你现在可以使用docker for mac内部IP.

[xdebug]
xdebug.remote_host = "docker.for.mac.host.internal"
xdebug.default_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_port = 9000
xdebug.idekey="PHPSTORM"

老配置

由于你在mac上使用docker我发布我的解决方案的工作方式.大部分学分都是this post on the docker forum.

假设您的xdebug安装正确,这是我在PHP.ini中的配置.

[xdebug]
xdebug.remote_host=10.254.254.254
xdebug.remote_autostart=1
xdebug.idekey = PHPSTORM
xdebug.default_enable = 0
xdebug.remote_enable = 1
xdebug.remote_connect_back = 0
xdebug.profiler_enable = 1

您可以在终端中执行此命令来测试配置. sudo ifconfig en0别名10.254.254.254 255.255.255.0.

如果这样做,您可以将其转换为plist文件并将其放在以下位置. /Library/launchdaemons/com.docker.xdebugFix.plist.您将在下面找到我的plist文件版本.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.docker.xdebugFix</string>
    <key>ProgramArguments</key>
    <array>
        <string>ifconfig</string>
        <string>en0</string>
        <string>alias</string>
        <string>10.254.254.254</string>
        <string>255.255.255.0</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

注意:plist仅在重启Mac后才能工作.

PHPSTORM配置(2018年编辑后也需要)

之后我用这样的调试服务器设置我的PHP风暴:

php storm config 1

php storm config 2

在那之后我的断点在哪里工作,如果你正在使用chrome你也需要使用xdebug扩展,但我很确定你知道这个,因为你过去使用过它.

相关文章

Docker是什么Docker是 Docker.Inc 公司开源的一个基于 LXC技...
本文为原创,原始地址为:http://www.cnblogs.com/fengzheng...
镜像操作列出镜像:$ sudo docker imagesREPOSITORY TAG IMA...
本文原创,原文地址为:http://www.cnblogs.com/fengzheng/p...
在 Docker 中,如果你修改了一个容器的内容并希望将这些更改...
在Docker中,--privileged 参数给予容器内的进程几乎相同的权...