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

How can I debug my docker container with phpStorm


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.


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 }'


I found more automated solutionIn my ENTRYPOINT i ran the startServices script

#!/bin/bashHOST_IP=`/sbin/ip route | awk '/default/ { print $3 }'`head -n -1 /etc/php5/mods-available/xdebug.ini > /etc/php5/mods-available/xdebug.tmpecho "xdebug.remote_host="$HOST_IP >> /etc/php5/mods-available/xdebug.tmprm /etc/php5/mods-available/xdebug.inimv /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=999xdebug.remote_autostart=truexdebug.remote_enable = Onxdebug.remote_connect_back = Offxdebug.remote_port = 9000xdebug.remote_handler=dbgpxdebug.remote_mode=reqxdebug.var_display_max_data = 2048xdebug.var_display_max_depth = 128xdebug.max_nesting_level = 500xdebug.remote_host=127.0.0.1

After running the script, i`ll get something like this

zend_extension=xdebug.so[xdebug]; priority=999xdebug.remote_autostart=truexdebug.remote_enable = Onxdebug.remote_connect_back = Offxdebug.remote_port = 9000xdebug.remote_handler=dbgpxdebug.remote_mode=reqxdebug.var_display_max_data = 2048xdebug.var_display_max_depth = 128xdebug.max_nesting_level = 500xdebug.remote_host=172.17.0.1

Where 172.17.0.1 is my current host ip