duandu2159 2016-07-07 18:37
浏览 64
已采纳

如何调试安装到在docker beta for mac上运行的容器的php

I have spent half the day trying different things including this solution I came across on gist.github.com

I have a docker-compose file which mounts a folder containing my client and server projects:

 volumes:
    - ~/projectx:/projectx

my docker php.ini contains the following xdebug options

[xdebug]
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_connect_back=On
xdebug.var_display_max_children = 999
xdebug.var_display_max_data = 999
xdebug.var_display_max_depth = 100

I have the xdebug chrome extension installed

In my mac host file I have the following 127.0.0.1 localhost dtest.xxx.com so I can access my web app (and other docker web apps) through dtest.xxx.com which all works to run the app

In Phpstorm (version 2016.1.2) In preferences -> Languages & Frameworks -> PHP -> Servers I have :

host = dtest.xxx.com, port=80 , Debugger = Xdebug
Use path mappings is checked and I have
      File/Directory set to /Users/<myname>/projectx/server
      Absolute path on the server is set to /projectx/server

I have tried setting the xdebug.remote_host to my macs ip obtained from ifconfig as well as trying the ip in /Users/<myname>/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/slirp/host

But I cannot hit a breakpoint , I have even added xdebug_break() double check. I am also running the latest docker beta Version 1.12.0-rc3-beta18 (build: 9996)

I would very much appreciate anyone's help, it's a real blocker for me.

If any further information is required I am happy to provide.

  • 写回答

1条回答 默认 最新

  • doubo4336 2016-07-08 13:08
    关注

    UPDATE 2:

    As pointed out by @Rashidul , Since 17.06 docker for Mac, you can replace xdebug.remote_host="192.168.65.1" with xdebug.remote_host="docker.for.mac.localhost"

    UPDATE: The Correct way

    so I eventually figured out that my xdebug settings in docker should be

    xdebug.enable=1
    xdebug.remote_enable = 1
    xdebug.idekey="PHPSTORM"
    xdebug.remote_port=9000
    xdebug.remote_host="192.168.65.1"
    xdebug.remote_connect_back=0
    

    where 192.168.65.1 is the entry found in ~/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/slirp/host

    In recent update the above no longer exists, to get the Docker host IP I know use the below my .profile

    export DOCKER_HOST_IP=$(ipconfig getifaddr en0)
    

    Also make sure to set the idekey correctly in the chrome extension, in my case PHPSTORM
    With this I no longer require the ssh tunnel

    Original Solution:

    The workaround I used was to open up an ssh tunnel to the docker container running php using a command like, in my case I have the docker container ssh port mapped to 12 hence the -p 12

    ssh -R 9000:localhost:9000 root@dtest.xxx.com -p:12
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿