Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xdebug can't connect back to Docker host

I've just setup Docker on my machine & have an Nginx/PHP7 (FPM)/MySQL setup all working fine, but having installed Xdebug on the PHP container I can't get it to connect back to PHPStorm on my host machine.

Here's my PHP Xdebug config…

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-
20151012/xdebug.so
xdebug.remote_log=/usr/local/var/log/xdebug.log
xdebug.remote_enable=1
xdebug.remote_host=192.168.99.1
xdebug.remote_port=9000
xdebug.remote_connect_back=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true

When browsing, with the Xdebug enable cookie set for the container, there's no prompt for a connection. If I browse a locally hosted site, there is, so I know PHPStorm's listening correctly.

On the local machine, I can telnet to port 9000…

$ telnet 192.168.99.1 9000
Trying 192.168.99.1...
Connected to 192.168.99.1.
Escape character is '^]'.
^]
telnet> quit
Connection closed.

… however I cannot from either the boot2docker VM, or the container. When I try it just sits there doing nothing. Both the VM and the container can, however, ping the host machine just fine.

I've tried disabling my Mac's firewall, but still no joy.

I'm not quite sure how to disable the firewall on the boot2docker VM.

Any insight into why this won't work would be greatly welcomed. Thanks in advance.

like image 886
TobyG Avatar asked Jul 04 '16 21:07

TobyG


1 Answers

Xdebug recommended config inside Container:

zend_extension = xdebug.so
xdebug.remote_enable = 1
xdebug.remote_connect_back = 0
xdebug.remote_host = docker.for.mac.localhost
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.remote_mode = req
xdebug.remote_autostart = 1
xdebug.idekey = PHPSTORM

Since Docker-17.06, you can access services hosted on Mac inside Container, via the static host name: docker.for.mac.localhost

I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST ?
The Mac has a changing IP address (or none if you have no network access). From 17.06 onwards our recommendation is to connect to the special Mac-only DNS name docker.for.mac.localhost which resolves to the internal IP address used by the host.

see https://docs.docker.com/docker-for-mac/networking/#i-cannot-ping-my-containers

like image 163
Lyfing Avatar answered Sep 19 '22 10:09

Lyfing