我知道有很多像这样的问题。不幸的是,这些答案都不适合我。
环境:
Dockerfile:
FROM php:7.0-apache
RUN apt-get update \
&& apt-get install -y \
net-tools \
&& pecl install \
xdebug-2.5.0 \
&& docker-php-ext-enable \
xdebug \
&& echo "ServerName localhost" >> /etc/apache2/apache2.conf \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_log=/var/log/xdebug.log" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=1" >> /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_host=172.17.0.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_autostart=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.idekey=xdebug-atom" >> /usr/local/etc/php/conf.d/xdebug.ini
的src / index.php的:
<?php
var_dump($_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR']); // <-- breakpoint is set at this line. However, does not fire in IDE. var_dump() output: null, 172.17.0.1
xdebug_break(); // function is recognized, however, does not have any effect
phpinfo();
启动容器的命令:
$ docker build -t xdebug . && docker run -d -p 80:80 -v /path/to/project/src/:/var/www/html/ --name xdebug_container xdebug
在浏览器中调用“localhost”时的结果:
我尝试过的变化:
背景信息 php-debug适用于MAMP Pro的xdebug
phpinfo xdebug部分:
xdebug support enabled
Version 2.5.0
IDE Key xdebug-atom
Supported protocols Revision
DBGp - Common DeBuGger Protocol $Revision: 1.145 $
Directive Local Value Master Value
xdebug.auto_trace Off Off
xdebug.cli_color 0 0
xdebug.collect_assignments Off Off
xdebug.collect_includes On On
xdebug.collect_params 0 0
xdebug.collect_return Off Off
xdebug.collect_vars Off Off
xdebug.coverage_enable On On
xdebug.default_enable On On
xdebug.dump.COOKIE no value no value
xdebug.dump.ENV no value no value
xdebug.dump.FILES no value no value
xdebug.dump.GET no value no value
xdebug.dump.POST no value no value
xdebug.dump.REQUEST no value no value
xdebug.dump.SERVER no value no value
xdebug.dump.SESSION no value no value
xdebug.dump_globals On On
xdebug.dump_once On On
xdebug.dump_undefined Off Off
xdebug.extended_info On On
xdebug.file_link_format no value no value
xdebug.force_display_errors Off Off
xdebug.force_error_reporting 0 0
xdebug.halt_level 0 0
xdebug.idekey xdebug-atom xdebug-atom
xdebug.max_nesting_level 256 256
xdebug.max_stack_frames -1 -1
xdebug.overload_var_dump 2 2
xdebug.profiler_aggregate Off Off
xdebug.profiler_append Off Off
xdebug.profiler_enable Off Off
xdebug.profiler_enable_trigger Off Off
xdebug.profiler_enable_trigger_value no value no value
xdebug.profiler_output_dir /tmp /tmp
xdebug.profiler_output_name cachegrind.out.%p cachegrind.out.%p
xdebug.remote_addr_header no value no value
xdebug.remote_autostart On On
xdebug.remote_connect_back On On
xdebug.remote_cookie_expire_time 3600 3600
xdebug.remote_enable On On
xdebug.remote_handler dbgp dbgp
xdebug.remote_host localhost localhost
xdebug.remote_log /var/log/xdebug.log /var/log/xdebug.log
xdebug.remote_mode req req
xdebug.remote_port 9000 9000
xdebug.scream Off Off
xdebug.show_error_trace Off Off
xdebug.show_exception_trace Off Off
xdebug.show_local_vars Off Off
xdebug.show_mem_delta Off Off
xdebug.trace_enable_trigger Off Off
xdebug.trace_enable_trigger_value no value no value
xdebug.trace_format 0 0
xdebug.trace_options 0 0
xdebug.trace_output_dir /tmp /tmp
xdebug.trace_output_name trace.%c trace.%c
xdebug.var_display_max_children 128 128
xdebug.var_display_max_data 512 512
xdebug.var_display_max_depth 3 3
有人知道如何处理或调试此问题吗?
更新
我停用xdebug.remote_connect_back并将xdebug.remote_host设置为我主机的私有IP。现在主机上的Wireshark中显示了一个连接。但是,容器的TCP [SYN]后面跟着主机的TCP [RST,ACK]。似乎Atom不接受连接。
答案 0 :(得分:1)
经过一些繁琐的调试后,我自己找到了答案:
基本问题是容器和主机设置不完全匹配。
Atom在主机上的php-debug设置:
在容器(= Dockerfile)上: