使用phpstorm对docker中的脚本进行debug

在对运行在容器中的环境进行debug,可以通过网页和脚本俩种方式进行debug,
这里介绍下对容器中的脚本进行debug。

首先,容器中的php环境需要有安装好xdebug扩展并且配置好,这里对应的image名称为php_sk。
《使用phpstorm对docker中的脚本进行debug》

这是运行的容器,/etc/docker/daemon.josn为使用api访问docker的配置(目的是使phpstorm能访问到容器)
,这里由于是测试环境,没做访问控制。

《使用phpstorm对docker中的脚本进行debug》

虚拟机安装在VirtualBox里,网络为NAT模式,通过端口转发和内部进行通信

《使用phpstorm对docker中的脚本进行debug》

通过对端口2375的转发,浏览器可以访问到api

《使用phpstorm对docker中的脚本进行debug》

设置debug端口,默认9000

《使用phpstorm对docker中的脚本进行debug》

配置phpstorm里的docker访问参数

《使用phpstorm对docker中的脚本进行debug》

这时候可以看到虚拟机中的容器,可以进行启动,暂停,和访问

《使用phpstorm对docker中的脚本进行debug》

《使用phpstorm对docker中的脚本进行debug》

选择php版本,和命令行访问模式,选择docker,找到php对应的image

《使用phpstorm对docker中的脚本进行debug》

配置对应的目录,设置的name,在后面执行脚本会使用到

《使用phpstorm对docker中的脚本进行debug》

配置debug,由于是命令行执行脚本,选择php script

《使用phpstorm对docker中的脚本进行debug》

连接至虚拟机,执行脚本(/home/www/sk/html/index.php),ip替换成phpstorm所在主机的ip

docker run --rm -v /home/www:/home/www --env "XDEBUG_CONFIG=remote_host=10.249.22.204 remote_port=9010"  --env "PHP_IDE_CONFIG=serverName=new" php_sk php /home/www/sk/html/index.php

《使用phpstorm对docker中的脚本进行debug》

可以看到,已经可以对脚本进行debug了

    原文作者:搬砖大叔
    原文地址: https://segmentfault.com/a/1190000016185886
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞