您在哪里可以找到Xdebug + Docker的问题?

时间:2020-05-22 08:39:45

标签: docker docker-compose xdebug

当我监听主机的端口9000(使用tcpdump)并向docker容器的URL(仅http://localhost:80)发出请求时,我看到此时捕获了2个数据包。但是,当我在用PhpStorm或xdebug's command line debug client(无参数)收听时,它们没有任何反应。

当我禁用容器中的xdebug(通过注释xdebug.remote_enable=1)并发出请求时,主机的端口9000没有任何反应,这使我认为xdebug正常工作。

当我在本地运行相同的代码时,相同的xdebug命令行工具(也没有参数)确实开始调试,这使我认为我使用了正确的工具。

我确实尝试遵循容器xdebug.remote_host文件中的IP,以xdebug.ini的形式出现(相同的结果):

  • 172.17.0.1(通过在主机上运行ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+'返回)
  • 172.18.0.1(通过在容器中运行/sbin/ip route|awk '/default/ { print $3 }'返回)
  • ≈10个其他人,我不记得自己是怎么得到的(尝试了很多事情)

我想念什么?我应该检查什么?


在主机上:

> php -v
PHP 7.4.6 (cli) (built: May 14 2020 10:02:44) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies
    with Xdebug v2.9.5, Copyright (c) 2002-2020, by Derick Rethans
    with blackfire v1.34.0~linux-x64-non_zts74, https://blackfire.io, by Blackfire



> sudo netstat -ltnp | grep -w ":9000"
tcp6       0      0 :::9000                 :::*                    LISTEN      20230/./dbgpClient

在Docker容器中:

> php -v
PHP 7.0.33-27+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Apr 19 2020 08:00:54) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.33-27+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.8.1, Copyright (c) 2002-2019, by Derick Rethans



> cat /etc/php/7.0/mods-available/xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_autostart = 1
xdebug.remote_host = 172.17.0.1
xdebug.remote_log = /var/www/html/xdebug.log



> ls -la /etc/php/7.0/fpm/conf.d/20-xdebug.ini
lrwxrwxrwx 1 root root 38 May  5 10:46 /etc/php/7.0/fpm/conf.d/20-xdebug.ini -> /etc/php/7.0/mods-available/xdebug.ini



> php -m |grep xdebug
xdebug



> cat /var/www/html/xdebug.log
[6] Log opened at 2020-05-22 11:47:38
[6] I: Connecting to configured address/port: 172.17.0.1:9000.
[6] E: Time-out connecting to client (Waited: 200 ms). :-(
[6] Log closed at 2020-05-22 11:47:38

捕获的错误数据包的内容(从容器发送,未打开dbgp客户端):

> sudo tcpdump -i any -vv port 9000
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
10:25:21.213336 IP (tos 0x0, ttl 64, id 22110, offset 0, flags [DF], proto TCP (6), length 60)
    192.168.220.2.56070 > machine.9000: Flags [S], cksum 0x48ec (incorrect -> 0xdbca), seq 3695390688, win 64240, options [mss 1460,sackOK,TS val 3734519707 ecr 0,nop,wscale 7], length 0
10:25:21.213351 IP (tos 0x0, ttl 64, id 22110, offset 0, flags [DF], proto TCP (6), length 60)
    192.168.220.2.56070 > machine.9000: Flags [S], cksum 0x48ec (incorrect -> 0xdbca), seq 3695390688, win 64240, options [mss 1460,sackOK,TS val 3734519707 ecr 0,nop,wscale 7], length 0
^C
2 packets captured
2 packets received by filter
0 packets dropped by kernel

正确捕获的数据包的内容(从主机发送,也无需dbgp客户端侦听):

> sudo tcpdump -i any -vv port 9000
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
12:19:39.842408 IP (tos 0x0, ttl 64, id 61242, offset 0, flags [DF], proto TCP (6), length 60)
    localhost.60404 > localhost.9000: Flags [S], cksum 0xfe30 (incorrect -> 0x158b), seq 743066778, win 65495, options [mss 65495,sackOK,TS val 3009412885 ecr 0,nop,wscale 7], length 0
12:19:39.842418 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 40)
    localhost.9000 > localhost.60404: Flags [R.], cksum 0x29cc (correct), seq 0, ack 743066779, win 0, length 0
^C
2 packets captured
12 packets received by filter
1 packet dropped by kernel

(不同输出中的时间戳有所不同,因为我去除了重复的部分)

0 个答案:

没有答案