V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
conn4575
V2EX  ›  程序员

开发环境使用 docker,如何正确的调试

  •  
  •   conn4575 · 2017-11-06 22:55:54 +08:00 · 4045 次点击
    这是一个创建于 2334 天前的主题,其中的信息可能已经有所发展或是发生改变。

    主要开发语言是 php 和 python,使用 docker 切换版本确实很方便,但是调试就蛋疼了,现在全靠 print 调试。。

    6 条回复    2017-11-07 11:19:15 +08:00
    fzinfz
        1
    fzinfz  
       2017-11-06 23:00:27 +08:00
    X11 Forwarding
    pubby
        2
    pubby  
       2017-11-06 23:03:13 +08:00
    phpstorm 远程调试啊
    zeq
        3
    zeq  
       2017-11-07 00:41:12 +08:00
    最基本的 volumes 要设置好,然后:

    ipython

    %pdb
    %debug
    dangyuluo
        4
    dangyuluo  
       2017-11-07 00:50:38 +08:00
    我已经放弃调试了
    gouchaoer
        5
    gouchaoer  
       2017-11-07 11:17:05 +08:00
    php 在 docker 里面可以通过 xdebug 连上宿主的 IDE 调试啊,做法类似这样:
    ```
    @unlink("/etc/php.d/xdebug.ini");
    $my_xdebug = "/etc/php.d/my_xdebug.ini";
    if(!file_exists($my_xdebug))
    {
    $HOST_IP=null;
    exec("ip route", $o, $r);
    echo implode(PHP_EOL, $o) . PHP_EOL;
    foreach ($o as $line)
    {
    $res = preg_match("/default.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $line, $matches);
    if($res)
    $HOST_IP=$matches[1];
    }
    //$HOST_IP is not always correct. If wrong you should manually find your host's ip in container to use xdebug.
    if(empty($HOST_IP))
    {
    die("failed to exec 'ip route' to get HOST's ip");
    }
    $xdebug_ini=<<<EOL
    ; Enable xdebug extension module
    zend_extension=/usr/lib64/php/modules/xdebug.so
    xdebug.remote_enable = 1
    xdebug.remote_handler = "dbgp"
    xdebug.remote_host = "{$HOST_IP}"
    EOL;
    ```
    gouchaoer
        6
    gouchaoer  
       2017-11-07 11:19:15 +08:00   ❤️ 1
    简单的说就是在 docker 容器中找到 host 的 ip,然后在 xdebug 中设置连 host 的 ip 就 ok 了。。。。如果你 docker 泡在 win7/win10 里面,因为本身 hyper 虚拟机还有一个路由,所以这个不准,你需要手动查看 hyper 虚拟机路由中 host 的 ip,然后设置
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1773 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:34 · PVG 00:34 · LAX 09:34 · JFK 12:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.