Closed chx closed 2 years ago
ooh, I think this has come up before - linux doesn't natively support host.docker.internal (at least consistently) - there are a few options at https://stackoverflow.com/questions/48546124/what-is-linux-equivalent-of-host-docker-internal/67158212
Yes, understanding docker networking is a PITA.
We recently released images with xdebug changes, was this working previously or is this the first time you've tried? It might not be relevant if you're having host connection issue, but might be worth a shot to update the images and try again.
In our xdebug troubleshooting docs I added a section about testing the docker network that works for most people that have tried
Verify that Docker for Mac networking is not broken. On your host machine, run
nc -l 9000
, then in a new terminal window, run:docker-compose run cli nc -zv host.docker.internal 9000
You should see a message like:host.docker.internal (192.168.65.2:9000) open
.
I don't know how docker for windows handles host.docker.internal
, but the php image will fallback to an ip address if host.docker.internal
doesn't resolve. You can try checking the phpinfo()
to see what what xdebug.client_host
it configured.
In an answer to that SO question Toby linked they mention being able to add --add-host=host.docker.internal:host-gateway
, can you tried that? If it works, maybe we can integrate that into lagoon somehow?
services:
cli:
build:
context: .
dockerfile: cli.dockerfile
extra_hosts:
- "host.docker.internal:host-gateway"
That didn't change anything. I still get:
telnet host.docker.internal 9999
telnet: can't connect to remote host (192.168.65.2): Connection refused
192.168 looks odd to me. I do not see anything in the routing table that would make it special.
ip rule
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
[smartsheet-www]cli-drupal:/app$ ip route show
default via 172.18.0.1 dev eth0
172.18.0.0/16 dev eth0 scope link src 172.18.0.4
Huh
I will continue investigating tomorrow but nc -l 12345
on host and telnet host.docker.internal 12345
actually works.
I will check whether it does with extra_hosts.
And then I guess the problem mutates into why nc works and phpstorm doesn't.
WILD.
I figured it out.
We need to do the opposite of what https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html suggests. The article is outdated or projector sets it differently but it doesn't matter. Here's what works:
-Djava.net.preferIPv4Stack=true
line.This is absolutely wild because the socket opened has IPv4 and IPv6 modes both -- from Windows or WSL I could connect by IPv4 address -- but that's just not enough for docker. It needs to be IPv4 only as best as I can tell. Also, extra_hosts
is unnecessary, it works without.
How's that.
Nice digging - glad it wasn't anything too docker - it gets pretty gnarly in WSL2 land
Although I am running Docker Desktop + WSL v2 I do not think that's relevant because docker itself runs inside the Linux VM provided by WSL v2.
With that said, any
telnet host.docker.internal 1234
no matter the port doesn't connect, it gives me connection refused.I tried to run projector as a docker container and
docker run --network=www_default --name phpstorm -v ~/workspace/www:/app -p 8887:8887 -it jetbrains/projector-phpstorm
does work butdocker run --network=www_default --name amazeeio-network -v ~/workspace/www:/app -p 8887:8887 -it jetbrains/projector-phpstorm
does not. amazeeio-network is pygmy created, www_default the default network created by docker-compose for our docker-compose which only has this about networks:This is so far beyond my docker knowledge it's not even funny.