Xdebug can't connect back to Docker host

我怕爱的太早我们不能终老 提交于 2020-01-03 21:13:33

问题


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.


回答1:


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




回答2:


You need to use a network that is bridged from your Docker host to your Mac. Do ifconfig on the Mac and look for the local IP on other local networks, e.g., 10.0.1.13. (The specifics may differ by version of Docker, but this worked with a Vagrant as Docker host and should work for most VMs.)



来源:https://stackoverflow.com/questions/38192502/xdebug-cant-connect-back-to-docker-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!