I use Docker Desktop 4.39 in wsl2. I try to resolve my mdns names of local network. I can do it successfully except hostname of host machine with docker itself.
If I understand correct, I see in wsl2 this output
$ ping HostHostname
127.0.1.1
And in docker container
$ ping HostHostname
ping: bad address "HostHostname"
So looks like that 127.0.1.1 address is redirected to 127.0.0.11 docker resolver, but 127.0.1.1 address is omitted on low level because this is just about host hostname.
I’ve found a way out to run container with docker --hostname HostHostname. But this is not the best way because I will not be able to achieve the container by its name in docker inner networks between containers.
That is just set in your hosts file (/etc/hosts) which will not be set in containers running in another WSL distribution (docker-desktop) and since loopback IPs are pointing back to their own network namespace, and containers have their own (not to mention the different WSL distribution), it wouldn’t work from containers even if you got the same loopback IP from a container.
/etc/hosts is automatically mounted from the host, not part of the image filesystem. Of course it will mount one only from inside the virtual machine, but if you want to add host IP mappings, you can add extra_hosts in compose or use --add-host with docker run.
Then it looks like I still don’t understand the issue. Why would you try to set a loopback IP address to the hostname of the host when using the hostname from a container? But if it was your intention, then yes, use the loopback IP what you quoted in your message and ignore what I wrote before. If you test it and it works as intended, then it is what you need to do.
I can do upstreams in nginx, for example, that contain all servers in my local network. And I can want to put the same nginx on a few machines. It will be problematically to set “localhost” or “host.docker.internal” for each server in nginx upstream where it matches with current machine mdns domain name.