Sorry for the delay, but I think I have a handle on both what’s going on and how we can fix it. With host networking, the hostname is obviously changed to the device’s hostname, rather than the container having a specific one. As you’ve mentioned, it doesn’t appear in the balenaOS container’s /etc/hosts file.
On my desktop:
[8:54] test-repos/network λ docker run -it --net host balenalib/amd64-debian /bin/bash
root@Thor:/# cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 Thor
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
on a balena device:
root@ab3d181:~# balena exec -it main_1_1 bash
bash-4.4# cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
My first thought was that the extraHosts
field in the container create endpoint has some special meaning when null
compared to an empty array []
(docker defaults to the former, but the supervisor defaults to the latter). I made the supervisor start using null as the default for this field, to no avail.
Other than the extraHosts
field, I can’t see any other option controlling the /etc/hosts
name. This leads me to believe that it’s either balenaEngine, or there’s some combination of options to container create that control this (documentation here: https://docs.docker.com/engine/api/v1.30/#operation/ContainerCreate)
Staying on the same thought process, I tried adding the following to the docker-compose of my host networked service:
extra_hosts:
- "ab3d181:127.0.0.1"
That’s my short uuid (or hostname) and the ip address it resolves to. And this works fine. So as a workaround, I’m sure we can get the supervisor to add this field to the extra_hosts array when using host networking, but I would much rather discover why it’s missing in the first place. In any case, I’ve made an issue to track this: https://github.com/balena-io/balena-supervisor/issues/994
I’m going to raise this internally, to see the best way to tackle it, but again, thanks so much for bringing it up. It’s these little, easy to miss bugs that can really annoy users!