2

I'm a bit confused using Xdebug, Docker for Windows, and PhpStorm...

I have Xdebug configured in a container with PHP. Here is what appears in my php.ini from within this container :

xdebug.remote_enable=on
xdebug.remote_autostart=off
xdebug.idekey=PHPSTORM
xdebug.remote_port=9000
xdebug.remote_host=10.0.75.1
# xdebug.remote_connect_back=1

My Windows IP as seen by docker seems to be 10.0.75.1 (PHP shows 10.0.75.1 for $_SERVER['REMOTE_ADDR'] when visited from Windows). It's also the DockerNAT virtual device IP.

PHPStorm (on Windows) is listening to Xdebug on port 9000. I have bound port 9000 to 9000 for this container :

web:
    build: php5
    ports:
        - "80:80"
        - "9000:9000"

Windows firewall is off. Still, PHPStorm doesn't get any incoming connection from this container.

Therefore I tried to telnet it from different places :
when I telnet 10.0.75.1 9000 from windows it connects successfully when PHPStorm is listening and returns this error when it is not listening : "Could not open connection to the host on port 9000 : connect failed" . This makes perfect sense.
Same thing when I try from another computer on my local network, telnet 192.168.1.4 9000 works fine.
But from my Docker's web container even though I can successfully ping 10.0.75.1 and telnet this IP on port 80 either (it connects), on port 9000 it returns an error whether PHPStorm is listening or not :

root@fd60276df273:/var/www/html# telnet 10.0.75.1 9000
Trying 10.0.75.1...
telnet: Unable to connect to remote host: Connection timed out

I've tried to change Xdebug port to some random other numbers and it doesn't change anything...

Do you have any idea what could cause this issue ?

kro
  • 521
  • 6
  • 16
  • Have you looked at similar questions: http://stackoverflow.com/questions/32668258/xdebug-windows-docker-phpstorm .. or search for `[phpstorm] docker xdebug` here on SO? – LazyOne May 27 '16 at 08:31
  • Yes but I had it working with docker machine. Setup is different using docker for windows (beta) which runs more natively - without virtual box. – kro May 27 '16 at 08:33
  • I see. Thanks for clarifying it. – LazyOne May 27 '16 at 08:42

2 Answers2

1

i've finally got it to work ! the key was to set network_mode to host :
https://docs.docker.com/compose/compose-file/

docker-compose.yml :

version: '2'

services:
    web:
        build: php5
        ports:
            - "80:80"
        #links:
        #    - db:db
        network_mode: "host"
    db:
        image: mysql
        ports:
            - "3306:3306"
        environment:
            - MYSQL_ROOT_PASSWORD=root

after trying this i noticed that my container had an interface IPed 192.168.65.2
so i telneted 192.168.65.1 9000 and it worked !

php.ini :

xdebug.idekey=PHPSTORM
xdebug.remote_port=9000
xdebug.remote_host=192.168.65.1

i've selected "Expose container ports on localhost" (new option) in docker settings.
i can't use links any more, because of the specified network_mode. so i've opened port 3306 and i have to choose 192.168.65.1 as mysql host. i will probably find some workaround about this, but finally it works !

kro
  • 521
  • 6
  • 16
  • I wonder if this issue is fixed in the stable version of Docker for Windows. I am able to use Xdebug when using bridged networking. I did, however, have to open up TCP port 9000 to connections from 10.0.75.0/24 in Windows Firewall before it started working. – goodman Aug 12 '16 at 19:53
  • yes i switched to the stable version and i don't have this issue any more, using the default network mode. – kro Aug 20 '16 at 14:36
0

Instead of using an IP address you can use a standard hostname defined by docker:

xdebug.remote_host=host.docker.internal

This will prevent cross-platform (mac/win) issues.