Hi the experts,
If My docker-compose spec like above, from inside client container, I’m only able to do ping to serverhost.com. Is there any way to ping to subdomain like abc.serverhost.com?
The other containers do not see that extra_hosts, I mean from inside other containers you cannot see these sub domain. I solved my problem by adding the alias to the container. docker network connect --alias sub.serverhost.com multi-host-network server. Thanks
Note: docker is not responsible to handle dns outside the container networks.
I assume you are setting the domains as hostname and alias to test something.
When it comes to container to container communication, you can use the service name, the container name, the host name or the alias to communicate with another container in the same network. This feature is only available in user defined networks, which docker compose deployments always create for the compose project.
In the real world a dns server would be responsible to resolve domain names to your docker host (or a reverse proxy or load balancer in front of it). Many people run a traefik container as reverse proxy and only expose port 80 and 443 for traefik, and let traefik forward the traffic for a sub domain and/or path to a specific container.