toolbx-images / images

Community maintained container images to use with toolbx and distrobox
https://containertoolbx.org/
Apache License 2.0
342 stars 30 forks source link

tweak archlinux/Containerfile to edit nsswitch.conf #85

Closed bugthing closed 1 year ago

bugthing commented 1 year ago

I ran into an issue using this image and distrobox. When I created a new container it could not reference itself by its hostname.

$ hostname
terra
$ distrobox create archymcarch --image quay.io/toolbx-images/archlinux-toolbox
$ distrobox enter archymcarch
$ sudo pacman -S inetutils
$ hostname
archymcarch.terra
$ ping archymcarch.terra
ping: archymcarch.terra: Name or service not known

I found that if I moved myhostname directive it could do so. This PR tweaks the nsswitch.conf file so that myhostname is further to the start of the hosts: line

travier commented 1 year ago

Note that this image is in progress to be moved to the upstream project: https://github.com/containers/toolbox/tree/main/images/arch

Foxboron commented 1 year ago

And generally, it's better to figure out if this is something that belongs upstream with Archs /etc/nsswitch.conf instead of patching it inn the container image.

Foxboron commented 1 year ago

Quickly looking at it, it seems like resolve [!UNAVAIL=return] does the wrong thing as a podman container. In my case it queries the host resolved DNS service.

[fox@toolbox ~]$ ping -c 1 toolbox
^C
[fox@toolbox ~]$ ping -c 1 framework # this is the container hosts hostname
PING framework(framework (fe80::d0ee:adf2:2db:6d5b%wlp170s0)) 56 data bytes
64 bytes from framework (fe80::d0ee:adf2:2db:6d5b%wlp170s0): icmp_seq=1 ttl=64 time=0.035 ms

--- framework ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.035/0.035/0.035/0.000 ms
Foxboron commented 1 year ago

Poking upstream systemd about this. The recommended upstream file seems incompatible with how toolbox is actually mounting the resolved file into the container.

https://github.com/systemd/systemd/blob/main/factory/etc/nsswitch.conf

# Arch
hosts:      mymachines resolve [!UNAVAIL=return] files myhostname dns

# Fedora
hosts:      files myhostname mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns
bugthing commented 1 year ago

thanks for looking at this @Foxboron @travier Happy to close this PR .. or leave open for tracking, but yeah, best to be addressed upstream if poss :smile: