How do IDE communicate with Xdebug inside a container (Docker)?

Asked

Viewed 152 times

1

I have a network of containers created with docker-compose. The Xdebug settings are passed in part by the file .yml and in part by an archive .ini consumed by PHP.

I know that 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 in the IP 172.18.0.1, which is an internal network IP created by Docker (on my network Ips are 192.168.x.x).

In the hosts file of my computer I create entries in the format 127.0.0.1 example.com to access the site through the browser. Everything ok, except that Phpstorm never receives information from Xdebug, even with the most diverse confidings, even with the current configuration - that theoretically would connect back to any IP that has a Debugger turned on:

[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 understand the working of Xdebug, what is missing now is a way for it to send (from inside the container) the debugging information to 172.18.0.1:9000 and this information is received on my computer (192.168.x.x:9000). How to make this bridge?

1 answer

2


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

So with this change the final settings were 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. :-)

That means the connection was already being accepted by the bridge. So just set up Phpstorm to answer the server debug calls "remote": Run > Start Listening to PHP Debug Connections

Browser other questions tagged

You are not signed in. Login or sign up in order to post.