Xdebug无法连接回Docker主机 [英] Xdebug can't connect back to Docker host

查看:187
本文介绍了Xdebug无法连接回Docker主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我的机器上安装了Docker&具有Nginx/PHP7(FPM)/MySQL的设置都可以正常工作,但是在PHP容器上安装了Xdebug后,我无法使其连接回主机上的PHPStorm.

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.

这是我的PHP Xdebug配置...

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

浏览时,在为容器设置Xdebug启用cookie的情况下,没有提示建立连接的提示.如果我浏览本地托管的站点,则存在,所以我知道PHPStorm的侦听正确.

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.

在本地计算机上,我可以远程登录到端口9000…

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.

…但是我无法从boot2docker VM或容器中获取.当我尝试时,它只是坐在那里什么都不做.但是,VM和容器都可以ping通主机.

… 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.

我曾尝试禁用Mac的防火墙,但仍然没有乐趣.

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

我不太确定如何在boot2docker VM上禁用防火墙.

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.

推荐答案

Xdebug在容器内推荐的配置:

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

自Docker-17.06起,您可以通过静态主机名docker.for.mac.localhost

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

我要从主机连接到主机上的服务吗?
Mac的IP地址正在更改(如果没有网络访问权限,则没有IP地址).从17.06开始,我们的建议是连接到专用于Mac的特殊DNS名称docker.for.mac.localhost,它将解析为主机使用的内部IP地址.

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.

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

这篇关于Xdebug无法连接回Docker主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆