Remote Debugging with XDebug from inside a Docker Container does not work

♀尐吖头ヾ 提交于 2019-12-03 05:00:00

You can try with this configuration. php-apache build provide two method to compile and enable module php. It's nicer to use docker-php-ext-enable xdebug to set correct file configuration.

FROM php:5.4-apache

# Enable and configure xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN sed -i '1 a xdebug.remote_autostart=true' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_mode=req' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_handler=dbgp' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_connect_back=1 ' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_port=9000' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_host=127.0.0.1' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_enable=1' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

For me on a PHP, NGINX Docker environment using sublime, I got it to work with these settings:

xdebug.remote_enable = 1
xdebug.remote_mode = req
xdebug.remote_port = 9001
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal

The one that took me forever to figure out was to set the remote_host to host.docker.internal.

user3835452

close: xdebug.remote_connect_back=0 add: xdebug.remote_host=192.168.0.102[your docker host/machine IP]

If you don't want do change xdebug config in the container and want to make it work using xdebug.remote_connect_back=1 you can set the HTTP-Header X-Forwarded-For to the IP of host.docker.internal und thus defines PHP $_SERVER['HTTP_X_FORWARDED_FOR'] which xdebug prefers and uses as the client IP instead of $_SERVER['REMOTE_ADDR'].

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!