Here is what worked for me.
Inner Dock Container
Change xdebug configuration
# automatically start debugger on every request xdebug.remote_enable=1 xdebug.remote_autostart=1 xdebug.remote_port=9000
Make sure xdebug is working
At this point, try starting the PHP application. The log must contain such entries for each request:
I: Connecting to configured address/port: 127.0.0.1:9000 I: Connected to client. :-)
If you see something like this in the log, the remote_connect remote_connect or remote_connect_back files are not configured correctly.
I: Checking remote connect back address. I: Checking header 'HTTP_X_FORWARDED_FOR'. I: Checking header 'REMOTE_ADDR'. I: Remote address found, connecting to 172.18.0.1:9000. W: Creating socket for '172.18.0.1:9000', poll: Operation now in progress. E: Could not connect to client. :-(
I saw situations when Xdebug worked in the CLI, but not from the browser, when this problem appeared in the log, remote_connect_back = 0 fixed it.
Sshd configuration
To enable ssh tunneling in a container: edit / etc / ssh / sshd _conf and add:
GatewayPorts yes
Restart sshd if necessary (ideally this should be part of the Docker file).
On the host computer
Start reverse ssh tunnel
Run this command and open it on a separate terminal tab: ssh -p {container_22_port} -R 9000:localhost:1111 root@127.0.0.1
where {container_22_port} is the port on the host that is mapped to port 22 on the docker container. 9000 is the port used by Xdebug inside the container, port 1111, which the host will use to listen for Xdebug connections.
Test with netcat
At this point, you can verify that Xdebug actually transfers information from the docker container to the host machine. Run netcat to find out what is sent on port 1111 and run the php application:
nc -l 1111
You should see something like this:
<?xml version="1.0" encoding="iso-8859-1"?> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/magento2/index.php" language="PHP" xdebug:language_version="7.0.12" protocol_version="1.0" appid="1006" idekey="XDEBUG_ECLIPSE"><engine version="2.5.0rc1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2016 by Derick Rethans]]></copyright></init>
Configure PhpStorm
Opne File DefaultSettings , and there in Languages&Frameworks PHP Debug change Xdebug Debug port to 1111 (the one we used to open the ssh tunnel). PhpStorm should start accepting connections from xdebug at this point.
Are there any problems with this approach?