2016-08-25 14 views
7

後,我從泊塢窗機切換到多克的Mac XDebug的已停止工作。主機上的端口9000無法從具有xdebug的容器中訪問。
的php.ini
Xdebug的在泊塢窗不工作的Mac

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. :-(

是否解決我的問題?

回答

7

我有同樣的問題。這可能與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),該設備將循環回到本地主機。當你使用這個ip作爲遠程主機地址而不是由docker(127.0.0.1或172.17.0.2)分配的地址時,它應該做到這一點。按照this link的編碼解決方案

+0

Tnaks!它幫助了我! –

+3

謝謝。你發佈的要點(https://gist.github.com/ralphschindler/535dc5916ccbd06f53c1b0ee5a868c93)是完美的。 –

1

您的碼頭工人,compose.yml更改爲以下。

您將要暴露的端口9000,不綁定。同時更新你的xdebug ini到你的主機(mac)的ip而不是docker的ip。

我還添加了如何從你的Mac直接安裝Xdebug的文件到您的碼頭工人,這樣你就可以在飛行中進行更新。這允許你更多的控制,因爲你可能需要更新你的IP從移動到WiFi的基礎。 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