来自docker-compose的Docker容器不能再连接到主机上了

问题描述 投票:0回答:1

我有三个服务是由运行在 Windows 上的 docker-compose 创建的,其中一个是基于 PHP:7.2-apache.我可以在 PHPStorm 中使用 XDebug 调试正在运行的应用程序,但自从我复制了这个 docker-compose 后,我就再也不能了。

下面是XDEBUG_CONFIG变量的值。

idekey=phpstorm remote_host=192.168.0.18 remote_log=/var/log/xdebug/xdebug.log remote_port=9000

The remote_host 是主机的本机IP地址,你可以在以下结果中看到 ipconfig (对不起,是法语)。

Configuration IP de Windows

Carte Ethernet Ethernet :

   Suffixe DNS propre à la connexion. . . : 
   Adresse IPv6 de liaison locale. . . . .: fe80::e5d8:3f1c:32b0:d0ea%13
   Adresse IPv4. . . . . . . . . . . . . .: 192.168.0.18
   Masque de sous-réseau. . . . . . . . . : 255.255.255.0
   Passerelle par défaut. . . . . . . . . : 192.168.0.1

Carte Ethernet vEthernet (Commutateur par) 2 :

   Suffixe DNS propre à la connexion. . . :
   Adresse IPv6 de liaison locale. . . . .: fe80::b1c1:deaf:a8cd:a9b7%3
   Adresse IPv4. . . . . . . . . . . . . .: 172.31.145.129
   Masque de sous-réseau. . . . . . . . . : 255.255.255.240
   Passerelle par défaut. . . . . . . . . :

XDebug记录了这些信息

[53] Log opened at 2020-04-30 11:45:11
[53] I: Connecting to configured address/port: 192.168.0.18:9000.
[53] E: Time-out connecting to client (Waited: 200 ms). :-(
[53] Log closed at 2020-04-30 11:45:11

正在执行... route 命令在容器上打印出这个值。

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.240.0   U     0      0        0 eth0

我不知道XDebug正常工作时的默认网关是什么 但现在这个值是主机的默认网关,这正常吗?

我应该在我的docker-compose中配置一个网络吗?

谢谢你的帮助

windows docker networking docker-compose xdebug
1个回答
0
投票

经过一些更多的研究,我可以解决我的问题。

根据 Docker for Windows文档:

主机的IP地址发生了变化(如果你没有网络接入,则没有)。从18.03开始,我们的建议是连接到特殊的DNS名称。host.docker.internal,它解析到主机使用的内部IP地址。这是为了开发目的,在Docker Desktop for Windows之外的生产环境中无法工作。

于是将 XDEBUG_CONFIG 这种方式的变量。

idekey=phpstorm remote_host=host.docker.internal remote_log=/var/log/xdebug/xdebug.log remote_port=9000
© www.soinside.com 2019 - 2024. All rights reserved.