How to make the IDE communicate with xDebug inside a container (docker)?

1

I have a container network created with docker-compose . The xDebug settings are passed in part by the .yml file and partly by a .ini file consumed by PHP.

I know xdebug is installed correctly in the container because it appears in phpinfo() and modifies the error outputs. I also know from the access logs that the container sees the connections coming from the host on the IP 172.18.0.1 , which is an internal network IP created by Docker (in my network the IPs are 192.168.x.x ).

In the hosts file on my computer, I create entries in the format 127.0.0.1 example.com to access the site through the browser. Everything okay, except that PhpStorm never receives information from Xdebug, even with the most diverse configurations, even with the current configuration - which would theoretically connect back to any IP that has a connected debugger:

[Xdebug]
xdebug.idekey = PHPSTORM
xdebug.default_enable = 1
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_host = 172.18.0.1
xdebug.remote_log = /var/log/remote.log

If I understood xdebug well, what's missing now is a way to send debugging information to 172.18.0.1:9000 (from within the container) and this information is received on my computer ( 192.168.x.x:9000 ). How to make this bridge?

    
asked by anonymous 13.03.2017 / 04:28

1 answer

2

Searching a little more, I discovered that the xdebug.remote_host statement actually directs a X-HTTP-FORWARD-FOR header, which is all it takes to tell xdebug which IP to connect to. With a few more tests I discovered that it can connect to the IP of the Network Bridge. This bridge was automatically created when I set up Hyper-V to work with Docker.

So with this change the final configuration looks like this:

[Xdebug]
xdebug.idekey = PHPSTORM
xdebug.default_enable = 1
xdebug.remote_enable = 1
xdebug.remote_autostart = 0
# este é o IP da ponte de rede
xdebug.remote_host = 192.168.25.125
xdebug.remote_log = /var/log/xdebug/remote.log

and the xdebug log now shows

Log opened at 2017-03-13 13:18:41
I: Connecting to configured address/port: 192.168.25.125:9000.
I: Connected to client. :-)

This means that the connection was already being accepted by the bridge. Then you just set up PHPStorm to service "remote" server debug calls: Run > Start Listening to PHP Debug Connections

    
13.03.2017 / 15:26