Docker和XDebug不读取断点VSCode [英] Docker and XDebug not reading breakpoints VSCode

查看:393
本文介绍了Docker和XDebug不读取断点VSCode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我运行的是旧版本



我最近将docker更新到版本17.03.1,除了xDebug没问题之外,其他一切都没有问题。



我已经通过其存储库中的一个问题联系了vscode-php-debug的创建者,然后他指出我要用xdebug和或docker解决这个问题。



我的问题如下:



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



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





在那之后,我的断点开始工作,如果您使用的是chrome,则还需要使用xdebug扩展名,但是我我很确定您是从过去使用过的。


I have been using XDebug with PHP Version 7.0.* for the last 6 months on a MAC using remote debugging to a Docker container.

I was running an older version of docker that was using VirtualBox to VM for docker, all was working fine.

I recently updated docker to version 17.03.1 and have had nothing but issues with xDebug. I have contacted the creator of vscode-php-debug via an issue on his repository and he then pointed me to take the issue up with xdebug and or docker.

My issue is the following:

XDebug is running and working on my container, the xdebug log shows that it connects to my IDE but it simply closes the connection as if there are no breakpoints when I have breakpoints set in VSCode.

The issue I posted on vscode-php-debug can be found here

Which has a copy of my xDebug logs and VSCode debug logs... It shows that the connection is made but no breakpoints are hit.

I have read around a few blogs that docker now needs a loopback ip created for the connection to xdebug to work, which I have also tried and failed.

I'm finding it surprisingly hard to debug without a debugger after using one for so long.

I have tried many configs, reinstalled, rebooted, rebuilt images/containers and even have tried the docker and xdebug irc channels on freenode without any success.

解决方案

EDIT-2 2018

The remote_host value can now be changed to support all platforms:

xdebug.remote_host = "host.docker.internal"

EDIT-1 2018 It's no longer needed to use the plist fix. As pointed out in this gist: https://gist.github.com/chadrien/c90927ec2d160ffea9c4#gistcomment-2398281 you can now use the docker for mac internal 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"


OLD CONFIG

Since you are using docker on a mac I'm posting the way my solution worked. Most of the credits go to this post on the docker forum.

Assuming your installation of xdebug is correctly, this is my config in the 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

You can test your config by executing this command in your terminal. sudo ifconfig en0 alias 10.254.254.254 255.255.255.0.

If this is working you can convert it into a plist file and place it in the following location. /Library/LaunchDaemons/com.docker.xdebugFix.plist. Below you will find my version of the plist file.

<?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>

Note: The plist will only work after a reboot of your Mac.


PHPSTORM Config (also needed after the 2018 edit)

After that I set up my PHP storm with a debug server like this:

After that my breakpoints where working, if you're using chrome you'll also need to use the xdebug extension but I'm pretty sure you know this since you used it in the past.

这篇关于Docker和XDebug不读取断点VSCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆