How can I debug my docker container with phpStorm
Asked Answered
I

3

23

Under the following IP my Container run successful in my Webbrowser

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

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

http://img2.picload.org/image/iowdpww/xdebug.png

But my Breakpoints in my index.php are ignored? What is my mistake?

Problem is solve with help from Sergey

My new 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"
Indirection answered 5/6, 2015 at 13:42 Comment(4)
Maybe you should set ip your host machine in xdebug.remote_host?Ocasio
thx, I delete xdebug.remote_host=127.0.0.1 and set xdebug.remote_connect_back=OnIndirection
It might be useful for someone else, but I also had to set up path mappings to map the local files to where they're mounted in the container. Settings > Languages & Frameworks > PHP > Servers then add a new oneLocomobile
How are you running your container? I'm interested in port mapping mainly. Are you mapping container's port 9000 to port 9000 outside (-p 9000:9000)?Sizing
D
18

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. Also remote_connect_back won't work well probably. 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.

Dyun answered 5/6, 2015 at 14:53 Comment(2)
Enter the container running PHP end type this at the CLI: /sbin/ip route|awk '/default/ { print $3 }'Dorado
My default was 172.17.0.1Hulking
M
5

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. You can obtain the IP of your host executing in the container:

/sbin/ip route|awk '/default/ { print $3 }'
Morbific answered 17/11, 2015 at 23:3 Comment(1)
instead of above command you can also run ifconfig where docker daemon is running. docker0 inet addr:172.17.0.1 (an example)Hennie
T
0

I found more automated solution In my ENTRYPOINT i ran the startServices script

#!/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

My initial 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

Tuatara answered 18/7, 2016 at 18:53 Comment(2)
The remote IP (172.17.0.1) does not work for me too. I can get xdebug communicating with my IDE though if I set remote_host to the IP of my Docker virtual ethernet adapter. Might be related to this issue github.com/docker/for-win/issues/37Northumberland
You shouldn't hardcode the ip 172.17.0.1, entry script will do the trick for you, it will take the correct ip address automatically. I have checked this solution on about a 10 computers, and all the time it works perfectlyTuatara

© 2022 - 2024 — McMap. All rights reserved.