[英]How can I debug my docker container with phpStorm
Under the following IP my Container run successful in my Webbrowser 在以下IP下,我的容器在我的Webbrowser中成功运行
http://192.168.99.100:32775 http://192.168.99.100:32775
I have also create a volume to share files between my container and my filesystem 我还创建了一个卷来共享我的容器和我的文件系统之间的文件
docker run --name lampf -d -p 32775:80 -v /Users/sja/Sites/lamkepf2:/var/www/html --link=lampf_db:db codinglimo/apache_php540_gs_imgmck_pdflib9
Now I install also xDebug successful in my container with the following xdebug.ini 现在我使用以下xdebug.ini在我的容器中成功安装了xDebug
zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
xdebug.remote_enable=on
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.profiler_enable=0
xdebug.profiler_output_dir="/temp/profiledir"
PHPStorm is also configured PHPStorm也已配置
http://img2.picload.org/image/iowdpww/xdebug.png http://img2.picload.org/image/iowdpww/xdebug.png
But my Breakpoints in my index.php are ignored? 但是我的index.php中的断点被忽略了? What is my mistake?
我的错是什么?
Problem is solve with help from Sergey 问题是在谢尔盖的帮助下解决的
My new xdebug.ini 我的新xdebug.ini
zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
xdebug.remote_enable=on
#xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_connect_back=On
xdebug.remote_handler=dbgp
xdebug.profiler_enable=0
xdebug.profiler_output_dir="/temp/profiledir"
Your Docker container can't see your PHP Storm IDE with the IP 127.0.0.1, typically the host is 172.17.42.1 from within a container. 您的Docker容器无法通过IP 127.0.0.1查看您的PHP Storm IDE,通常主机是容器内的172.17.42.1。 Also remote_connect_back won't work well probably.
此外,remote_connect_back可能无法正常工作。 Try setting it up like this:
尝试设置如下:
xdebug.remote_host=172.17.42.1
xdebug.remote_connect_back=Off
You might need to look for a proper way to know the host's IP within your container, 172.17.42.1 is just the default but it might not always be that. 您可能需要寻找一种正确的方法来了解容器中的主机IP,172.17.42.1只是默认值,但可能并非总是如此。
It worked for me just executing inside the container: 它对我来说只是在容器内执行:
pecl install -o -f xdebug \
&& rm -rf /tmp/pear \
&& echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_host=172.17.42.1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_connect_back=On" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "memory_limit = 64M" > /usr/local/etc/php/conf.d/php.ini
And then, restarting the container. 然后,重新启动容器。
172.17.42.1 is the default IP of the host, when running Docker. 172.17.42.1是运行Docker时主机的默认IP。 You can obtain the IP of your host executing in the container:
您可以获取在容器中执行的主机的IP:
/sbin/ip route|awk '/default/ { print $3 }'
I found more automated solution In my ENTRYPOINT i ran the startServices script 我找到了更多的自动化解决方案在我的ENTRYPOINT中,我运行了startServices脚本
#!/bin/bash
HOST_IP=`/sbin/ip route | awk '/default/ { print $3 }'`
head -n -1 /etc/php5/mods-available/xdebug.ini > /etc/php5/mods-available/xdebug.tmp
echo "xdebug.remote_host="$HOST_IP >> /etc/php5/mods-available/xdebug.tmp
rm /etc/php5/mods-available/xdebug.ini
mv /etc/php5/mods-available/xdebug.tmp /etc/php5/mods-available/xdebug.ini
/usr/bin/supervisord
It takes the current ip address of the host machine and replaces the line in xdebug.ini, then running the supervisord witch is starting all the stuff 它需要主机的当前IP地址并替换xdebug.ini中的行,然后运行supervisord女巫正在启动所有的东西
My initial xdebug.ini 我最初的xdebug.ini
zend_extension=xdebug.so
[xdebug]
; priority=999
xdebug.remote_autostart=true
xdebug.remote_enable = On
xdebug.remote_connect_back = Off
xdebug.remote_port = 9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.var_display_max_data = 2048
xdebug.var_display_max_depth = 128
xdebug.max_nesting_level = 500
xdebug.remote_host=127.0.0.1
After running the script, i`ll get something like this 运行脚本后,我会得到这样的东西
zend_extension=xdebug.so
[xdebug]
; priority=999
xdebug.remote_autostart=true
xdebug.remote_enable = On
xdebug.remote_connect_back = Off
xdebug.remote_port = 9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.var_display_max_data = 2048
xdebug.var_display_max_depth = 128
xdebug.max_nesting_level = 500
xdebug.remote_host=172.17.0.1
Where 172.17.0.1 is my current host ip 172.17.0.1是我当前的主机ip
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.