xdebug无法在Docker Desktop for Mac中使用

时间:2016-08-25 11:16:37

标签: macos docker xdebug docker-for-mac docker-desktop

在我从 Docker Machine 切换到 Docker Desktop for Mac 后,xdebug已停止工作。主机上的端口9000无法从具有xdebug的容器中访问 的的php.ini

xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_host=172.18.0.1
xdebug.idekey=PHPSTORM

搬运工-compose.yml

version: '2'
services:
  php:
    image: <image name>
    ports:
      - 80:80
    # - 9000:9000
    volumes:
      - .:/var/www/html
      - ./php.ini:/usr/local/etc/php/conf.d/php.ini

xdebug.log

I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 172.18.0.1:9000.
E: Could not connect to client. :-(

Н解决我的问题?

3 个答案:

答案 0 :(得分:9)

我有同样的问题。它可能与OSX中docker的局限性有关。请参阅这些链接。

https://docs.docker.com/docker-for-mac/networking/ https://forums.docker.com/t/explain-networking-known-limitations-explain-host/15205

还提出了可能的解决方法。其中之一是创建一个带有新ip(例如10.254.254.254)的设备,该设备循环回到localhost。然后,当您使用此ip作为远程主机地址而不是docker(127.0.0.1或172.17.0.2)分配的地址时,它应该可以解决问题。关注this link以获取编码解决方案

答案 1 :(得分:1)

将docker-compose.yml更改为以下内容。

您希望公开端口9000,而不是绑定。还要将xdebug ini更新到主机(mac)的ip而不是docker的ip。

我还添加了如何将mac中的xdebug文件直接挂载到docker中,以便您可以即时更新它。这可以让你更加控制,因为你可能需要根据从wifi到wifi的更新你的IP。 xdebug.remote_host = ip应该是你的mac本地网络ip。只要记住,如果您在apache上执行service apache2 restart或适当的命令,以便在您更改ip时重新启动服务器。

version: '2'
services:
  php:
    image: <image name>
    ports:
      - 80:80
    expose:
      - "9000"
    volumes:
      - .:/var/www/html
      - ./php.ini:/usr/local/etc/php/conf.d/php.inivolumes:
      - ./20-xdebug.ini:/etc/php/7.1/cli/conf.d/20-xdebug.ini //obviously you would change this to your correct paths
      - ./20-xdebug.ini:/etc/php/7.1/apache2/conf.d/20-xdebug.ini //obviously you would change this to your correct paths


# 20-xdebug.ini, this is how mine is setup. 
zend_extension = /usr/lib/php/20160303/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=192.168.0.4 // Make sure you use your host (mac) local ip, not the ip of docker. 
xdebug.remote_port=9000
xdebug.idekey = PHPSTORM
xdebug.remote_handler = dbgp
xdebug.remote_autostart = 1
xdebug.remote_log = /var/log/xdebug.log

答案 2 :(得分:0)

我为此苦了一段时间,在阅读https://docs.docker.com/docker-for-mac/networking/#httphttps-proxy-support的官方文档后,我找到了一个更简单的解决方案 特别是这部分:

  

我想从主机连接到主机上的服务

     

主机的IP地址正在更改(如果您没有网络,则没有IP地址)   访问)。从18.03开始,我们的建议是连接到   特殊的DNS名称host.docker.internal,解析为内部   主机使用的IP地址。这是出于发展目的,将   在Docker for Mac以外的生产环境中无法使用。

一旦您了解了这一点,就可以在容器内的php.ini中将remote_host设置为host.docker.internal。同样不要忘记将xdebug.remote_connect_back设置为0,主机设置不会被忽略:

xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_log=/tmp/xdebug.log
xdebug.remote_host=host.docker.internal
xdebug.remote_enable=1
xdebug.remote_connect_back=0
相关问题