Host: ubuntu 22.04, docker image: php:7.2-fpm (+nginx:alpine), laravel: 5.2.
For some legacy laravel project I need to test some feature that uses sphinx. It's not configured locally so it's easier to connect to server where it's already working. I use docker for my local setup and I want to connect from docker container to sphinx that is on remote server using ssh port forwarding ssh -f -N <username>@<host> -L <port>:<ip>:<port>
In my docker-compose.yaml there is extra_hosts setting for accessing local machine from inside of the php container.
extra_hosts:
- "host.docker.internal:host-gateway"
Inside the vendor code it's trying to connect like this:
$conn = mysqli_init();
...
$conn->real_connect($data['host'], null, null, null, (int) $data['port']);
host is http://host.docker.internal.
It gives me an error:
mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution. Without http:// doesn't work as well.
If I try this directly on my local machine (host: 127.0.0.1) after forwarding port - connection is established, real_connect works just fine.
I feel like there should be a special service ip for my local host (additionally to host.docker.internal) or a way to set it up for that kind of thing.
UPD: if I use just host.docker.internal, mysqli gives me "Connection refused" error.
UPD2: Tried host gateway ip (172.25.0.1) from docker network inspect. Same "Connection refused".
root@e279887dc67b:/var/www# nslookup host.docker.internal
Server: 127.0.0.11
Address: 127.0.0.11#53
** server can't find host.docker.internal: NXDOMAIN
root@e279887dc67b:/var/www# nslookup 172.25.0.1
1.0.25.172.in-addr.arpa name = maksim-linux-laptop.
1.0.25.172.in-addr.arpa name = maksim-linux-laptop.local.