使用XDebug从Docker Container进行远程调试不起作用 [英] Remote Debugging with XDebug from inside a Docker Container does not work
问题描述
我正在尝试设置一个对接的AMP环境,无法让远程调试器工作。我的设置如下:
我有一个运行mysql的数据库容器,它的工作方式就像一个魅力。我使用以下Dockerfile构建了一个Docker映像phpmysqli
FROM php:apache
RUN docker -php-ext-install mysqli mbstring
#zend_extension = / usr / local / lib / php / extensions / no-debug-non-zts-20131226 / xdebug.so
运行pecl安装xdebug
RUN echo'zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so'>>> /usr/local/etc/php/php.ini
RUN touch /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_enable = 1>> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_autostart = 0>> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_connect_back = 1>> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_port = 9000>> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_log = / tmp / php5-xdebug.log>> /usr/local/etc/php/conf.d/xdebug.ini;
RUN echo'date.timezone = Europe / Berlin'> /usr/local/etc/php/conf.d/date.ini
我打电话给
docker run --rm -ti --name web -p 127.0.0.1:8080:80 -v / path / to / projects: / var / www / html --link db:db phpmysqli
此phpinfo分别为php -i显示xdebug 2.3.2已启动并正在运行。
接下来我在IntelliJ IDEA中设置了一个名为Docker的服务器,其中Host 127.0.0.1
,Port 8080
和Debugger Xdebug。我在Docker运行语句中设置了类似于Volume映射的路径映射。
在 PHP-> Debug设置中,我检查了我使用的端口 9000
用于传入连接,我将接受外部连接,我不会忽略来自未注册服务器的连接。
之后,我创建了一个名为Docker的新的PHP远程调试配置。服务器是Docker,会话ID是 XDEBUG_IDEA
。
我可以在Container上调用PHP文件,我可以连接到db通过链接...但是由于某种原因,当我尝试启动调试会话时,没有任何事情发生。我尝试使用一个cookie(是的,我设置 XDEBUG_IDEA
作为xdebug帮助程序中的会话ID)。我尝试发送 XDEBUG_SESSION_START = XDEBUG_IDEA
作为 GET
...
<你可以聪明的人告诉我我错过了什么吗?
您可以尝试使用此配置。 php-apache构建提供两种方法来编译和启用模块php。
使用 docker-php-ext-enable xdebug
设置正确的文件配置更好。
FROM php:5.4-apache
#启用并配置xdebug
运行pecl安装xdebug
RUN docker-php-ext-enable xdebug
运行sed -i'1 a xdebug.remote_autostart = true'/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
运行sed -i'1 a xdebug .remote_mode = req'/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
运行sed -i'1 a xdebug.remote_handler = dbgp'/ usr / local / etc /php/conf.d/docker-php-ext-xdebug.ini
运行sed -i'1 a xdebug.remote_connect_back = 1'/usr/local/etc/php/conf.d/docker-php- ext-xdebug.ini
运行sed -i'1 a xdebug.remote_port = 9000'/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
运行sed -i'1 a xdebug.remote_host = 127.0.0.1'/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
运行sed -i'1 a xdebug.remote_enable = 1'/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
I'm trying to setup a dockered AMP environment and can't get the remote debugger working. My setup is as follows:
I have a database container running mysql which is working like a charm. I built a Docker image 'phpmysqli' with the following Dockerfile
FROM php:apache
RUN docker-php-ext-install mysqli mbstring
# zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
RUN pecl install xdebug
RUN echo 'zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so' >> /usr/local/etc/php/php.ini
RUN touch /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_enable=1 >> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_autostart=0 >> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_connect_back=1 >> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_port=9000 >> /usr/local/etc/php/conf.d/xdebug.ini; \
echo xdebug.remote_log=/tmp/php5-xdebug.log >> /usr/local/etc/php/conf.d/xdebug.ini;
RUN echo 'date.timezone = Europe/Berlin' > /usr/local/etc/php/conf.d/date.ini
I call
docker run --rm -ti --name web -p 127.0.0.1:8080:80 -v /path/to/projects:/var/www/html --link db:db phpmysqli
After this phpinfo respectively php -i shows that xdebug 2.3.2 is up and running.
Next I setup a Server inside IntelliJ IDEA called 'Docker' with Host 127.0.0.1
, Port 8080
and Debugger Xdebug. I setup the path mapping analogous to the Volume mapping in the docker run statement.
In the PHP->Debug settings I checked that I use port 9000
for incoming connections, that I will accept external connections and that I will not ignore connections from unregistered servers.
After this I created a new PHP Remote Debug Configuration called Docker, too. Server is Docker, session id is XDEBUG_IDEA
.
I can call PHP files on the Container, I can connect to the db via the link... but for some reason nothing whatsoever happens when I try to start a debug session. I tried using a cookie (and yes, I set XDEBUG_IDEA
as session id in xdebug helper). I tried sending XDEBUG_SESSION_START=XDEBUG_IDEA
as GET
...
Can you smart people out there tell me what I missed?
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
这篇关于使用XDebug从Docker Container进行远程调试不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!