It is syntactically correct, but that is just hostname and it helps only if your targer service runs on the host network. I didn’t understand what your goal was when I wrote that part of my comment. But you are right, you can use that to access the service using a different IP address.
It doesn’t change the fact that you can’t use “host.docker.internal” instead of an IP address. You could use a script to detect the current ip address on the host or set it as an environment variable in a .env
file and use that variable in the docker-compose.yml
extra_hosts:
- "<some_service_name>:$HOSTIP"
I have a similar script for Linux, but I can’t write a compatible version for Mac now.