Docker Community Forums

Share and learn in the Docker community.

Docker for Mac: accessing machines host alias from inside a container

I am trying to access alias in my /etc/hosts from inside a docker container, I have used host.docker.internal but that resolves to localhost, my machines /etc/hosts looks like this:

#i can reach with using host.docker.internal
127.0.0.01       loclalhost

#cannot reach these hostnames
127.1.2.1        local-servce
127.1.2.2        local-postgres
127.1.2.4        local-redis
127.1.2.3        local-elasticsearch
127.1.2.5        local-grcp

I cannot call the host names from inside the container, where as on my Linux machine I am able to use network_mode: host. I understand that network_mode is not available for mac and there is the DNS name that is exposed to get localhost, but is there a way to connect to these hostnames?