简体   繁体   English

将 NetBeans 连接到 Docker 容器上的 Xdebug

[英]Connect NetBeans to Xdebug on a Docker container

I tried to connect NetBeans to Xdebug located in a container PHP within Ubuntu.我试图将 NetBeans 连接到位于 Ubuntu 内的容器 PHP 中的 Xdebug。

The problem is that if I launch the container with the option -.net=host everything is OK, but if I try use the default one (bridge), NetBeans can reach the container but the container can't reach my host environment.问题是,如果我使用选项-.net=host启动容器,一切正常,但如果我尝试使用默认的(网桥),NetBeans 可以到达容器,但容器无法到达我的主机环境。

This is my xdebug ini conf:这是我的 xdebug ini conf:

xdebug.remote_enable=1
xdebug.remote_connect_back=0
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.profiler_enable=0
xdebug.remote_log="/tmp/xdebug.log"

Notice that Xdebug log explicitly reports that xdebug can't find getadress.请注意,Xdebug 日志明确报告 xdebug 无法找到 getadress。

There is a way to connect a bridged container to host environment?有一种方法可以将桥接容器连接到主机环境吗?

Using Xdebug3, I am using the following settings in my xdebug.ini file:使用 Xdebug3,我在我的 xdebug.ini 文件中使用了以下设置:

zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=trigger
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.idekey="netbeans-xdebug"

The port number of 9003 matches the value set in Netbeans Preferences - PHP - Debugging - Debugger Port. 9003的端口号与Netbeans Preferences - PHP - Debugging - Debugger Port中设置的值相匹配。 I can't remember the default, but it's probably 9000.我不记得默认值,但它可能是 9000。

This assumes that you're using the default "bridged.network" mode for Docher.这假设您正在为 Docher 使用默认的“bridged.network”模式。 What's happening here is that host.docker.internal is telling Xdebug to connect to the container's host - ie your dev machine which is running Netbeans.这里发生的是host.docker.internal告诉 Xdebug 连接到容器的主机——即运行 Netbeans 的开发机器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM