I have development environment inside docker containers. I am trying to run Xdebug and connect to it from VSCode running on the host (Windows 10).
I tried to use in docker-compose
extra_hosts:
- "host.docker.internal:host-gateway"
But I got an error that invalid IP address in add-host: "host-gateway
After digging I found that it might be related to docker version 19. So I tried to upgrade.
Now I have weird situation:
from Windows cmd:
# docker -v
Docker version 20.10.8, build 3967b7d
from inside WSL:
$ docker -v
Docker version 19.03.8, build afacb8b7f0
Anyway, it didn't solve the problem.
Xdebug is installed in the container:
/var/www/html# php -v
PHP 5.6.40 (cli) (built: Jan 23 2019 00:10:05)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
This is the Xdebug log:
Log opened at 2021-11-04 20:58:06
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 172.20.112.1:9001.
E: Time-out connecting to client. :-(
Port 9001 is exposed in the dockerfile and in the docker-compose file.
Xdebug config:
xdebug.extended_info=on
xdebug.idekey=xdebug
xdebug.profiler_enable=off
xdebug.profiler_enable_trigger=on
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=host.docker.internal
xdebug.remote_log="/var/log/xdebug.log"
xdebug.remote_port=9001
but host.docker.internal
isn't even recognized:
# ping host.docker.internal
ping: host.docker.internal: Name or service not known
so where does 172.20.112.1
in the Xdebug log file coming from?
the container route:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 172.18.0.1 0.0.0.0 UG 0 0 0 eth0
172.18.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
the container hosts
file:
# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.3 myappname
The Windows routing table:
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.0.0.138 10.0.0.15 35
10.0.0.0 255.255.255.0 On-link 10.0.0.15 291
10.0.0.15 255.255.255.255 On-link 10.0.0.15 291
10.0.0.255 255.255.255.255 On-link 10.0.0.15 291
127.0.0.0 255.0.0.0 On-link 127.0.0.1 331
127.0.0.1 255.255.255.255 On-link 127.0.0.1 331
127.255.255.255 255.255.255.255 On-link 127.0.0.1 331
172.17.0.0 255.255.0.0 172.31.232.91 172.20.112.1 5001
172.18.0.0 255.255.0.0 172.31.232.91 172.20.112.1 5001
172.20.112.0 255.255.240.0 On-link 172.20.112.1 5256
172.20.112.1 255.255.255.255 On-link 172.20.112.1 5256
172.20.127.255 255.255.255.255 On-link 172.20.112.1 5256
172.28.128.0 255.255.255.0 On-link 172.28.128.1 281
172.28.128.1 255.255.255.255 On-link 172.28.128.1 281
172.28.128.255 255.255.255.255 On-link 172.28.128.1 281
192.168.48.0 255.255.240.0 On-link 192.168.48.1 5256
192.168.48.1 255.255.255.255 On-link 192.168.48.1 5256
192.168.63.255 255.255.255.255 On-link 192.168.48.1 5256
224.0.0.0 240.0.0.0 On-link 127.0.0.1 331
224.0.0.0 240.0.0.0 On-link 172.28.128.1 281
224.0.0.0 240.0.0.0 On-link 10.0.0.15 291
224.0.0.0 240.0.0.0 On-link 192.168.48.1 5256
224.0.0.0 240.0.0.0 On-link 172.20.112.1 5256
255.255.255.255 255.255.255.255 On-link 127.0.0.1 331
255.255.255.255 255.255.255.255 On-link 172.28.128.1 281
255.255.255.255 255.255.255.255 On-link 10.0.0.15 291
255.255.255.255 255.255.255.255 On-link 192.168.48.1 5256
255.255.255.255 255.255.255.255 On-link 172.20.112.1 5256
===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
172.17.0.0 255.255.0.0 172.31.232.91 1
172.18.0.0 255.255.0.0 172.31.232.91 1
If you need more info, please let me know