Files
Daniel Rudolf 6f9cc3755a Mention no_hosts and base_hosts_file configs in CLI option docs
Follow-up to #24043

Signed-off-by: Daniel Rudolf <github.com@daniel-rudolf.de>
2024-10-02 23:15:24 +02:00

2.2 KiB

####> This option file is used in: ####> podman build, create, farm build, pod create, run ####> If file is edited, make sure the changes ####> are applicable to all of those.

--add-host=hostname[;hostname[;...]]:ip

Add a custom host-to-IP mapping to the <<container|pod>>'s /etc/hosts file.

The option takes one or multiple semicolon-separated hostnames to be mapped to a single IPv4 or IPv6 address, separated by a colon. It can also be used to overwrite the IP addresses of hostnames Podman adds to /etc/hosts by default (also see the --name and --hostname options). This option can be specified multiple times to add additional mappings to /etc/hosts. It conflicts with the --no-hosts option and conflicts with no_hosts=true in containers.conf.

Instead of an IP address, the special flag host-gateway can be given. This resolves to an IP address the container can use to connect to the host. The IP address chosen depends on your network setup, thus there's no guarantee that Podman can determine the host-gateway address automatically, which will then cause Podman to fail with an error message. You can overwrite this IP address using the host_containers_internal_ip option in containers.conf.

The host-gateway address is also used by Podman to automatically add the host.containers.internal and host.docker.internal hostnames to /etc/hosts. You can prevent that by either giving the --no-hosts option, or by setting host_containers_internal_ip="none" in containers.conf. If no host-gateway address was configured manually and Podman fails to determine the IP address automatically, Podman will silently skip adding these internal hostnames to /etc/hosts. If Podman is running in a virtual machine using podman machine (this includes Mac and Windows hosts), Podman will silently skip adding the internal hostnames to /etc/hosts, unless an IP address was configured manually; the internal hostnames are resolved by the gvproxy DNS resolver instead.

Podman will use the /etc/hosts file of the host as a basis by default, i.e. any hostname present in this file will also be present in the /etc/hosts file of the container. A different base file can be configured using the base_hosts_file config in containers.conf.