Where would you look to find out problem with Xdebug+Docker?

Viewed 98

When I'm listening to port 9000 of my host machine (with tcpdump) and making request to docker container's URL (just http://localhost:80), I see 2 packets captured at that moment. But when I'm listening with PhpStorm or xdebug's command line debug client (with no arguments), they don't react in any way.

When I disable xdebug in container (by commenting out xdebug.remote_enable=1) and make request, nothing comes to port 9000 of the host, which makes me think that xdebug is working.

When I run same code locally, same xdebug command line tool (also with no arguments) does start debugging, which makes me think that I use correct tools.

I did try following IPs as xdebug.remote_host in container's xdebug.ini file (same result):

  • 172.17.0.1 (returned by running ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+' on host)
  • 172.18.0.1 (returned by running /sbin/ip route|awk '/default/ { print $3 }' in container)
  • ā‰ˆ10 others, which I don't remember how I got (tried lots of things)

What am I missing? And what should I check?


On host machine:

> 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

In Docker container:

> 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

Content of incorrect captured packets (sent from container, without dbgp client turned on):

> 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

Content of correct captured packets (sent from host, also without dbgp client listening):

> 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

(timestamps in different outputs differ, because I strip repeating parts)

0 Answers
Related