简体   繁体   中英

Connect NetBeans to Xdebug on a Docker container

I tried to connect NetBeans to Xdebug located in a container PHP within Ubuntu.

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.

This is my 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.

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:

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. I can't remember the default, but it's probably 9000.

This assumes that you're using the default "bridged.network" mode for Docher. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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