containers / podman

Podman: A tool for managing OCI containers and pods.
https://podman.io
Apache License 2.0
22.37k stars 2.31k forks source link

[Podman man] --no-hosts and base_hosts_file semantics #23031

Closed th-hummel closed 2 weeks ago

th-hummel commented 2 weeks ago

Discussed in https://github.com/containers/podman/discussions/22990

Originally posted by **th-hummel** June 12, 2024 Hello, running `podman-4.4.1` on `RHEL 8.8` or `podman-5.1.0` on `Fedora 40`: 1. `podman-run(1)` states: ``` --no-hosts Do not create /etc/hosts for the container. By default, Podman will manage /etc/hosts, adding the con‐ tainer's own IP address and any hosts from --add-host. --no-hosts disables this, and the image's /etc/hosts will be preserved unmodified. This option conflicts with --add-host. ``` 2. `containers.conf(5)` states: ``` base_hosts_file="" The hosts entries from the base hosts file are added to the containers hosts file. This must be either an absolute path or as special values "image" which uses the hosts file from the container image or "none" which means no base hosts file is used. The default is "" which will use /etc/hosts. ``` as a newcomer to those options I find the described semantics ambiguous and not consistent with what I can test with the two options combinatorics. From 1. I first had deduced that `--no-hosts` dealt only with adding or not the 2 container/container-to-host ip addresses (+ whatever was added with `--add-host`). If this was the case, ``` --no-hosts + base_hosts_file="" ``` would still put host `/etc/hosts` file in the container, which obviously is not the case. It seems that `--no-hosts` just makes the value of `base_hosts_file` irrelevant. You may reply that it's what `--no-hosts disables this, and the image's /etc/hosts will be preserved unmodified.` means but this does not seem clear to me given the first sentence. From2. (which states `are added`), I deduced that, (in case of default `""` and no `--no-hosts`) host's `/etc/hosts` would be appended to image's rootfs `/etc/hosts`, which again does not seem to be the case. It seems that host's `/etc/hosts` is "chosen" (then only container and network is added) over images's one Finally, it seems that no matter what podman still inserts ``` 127.0.0.1 localhost ::1 localhost ``` if (granted this is extreme scenario) no `127.0.0.1` or `::1` entry is found which of course is fine but differs from the default one could find for instance in `ubi` which is: ``` 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 ``` It may be just me. Or maybe doc could use some clarification : what do you think ? Thanks for your help -- Thomas HUMMEL
Luap99 commented 2 weeks ago

Let's keep the conversation in the discussion https://github.com/containers/podman/discussions/22990