Skip to content

Commit cd4f09c

Browse files
Merge pull request #2184 from PhrozenByte/docs-hosts-file
Update docs of `containers.conf` configs affecting `/etc/hosts`
2 parents 4ec1f72 + 1069ef5 commit cd4f09c

File tree

2 files changed

+59
-26
lines changed

2 files changed

+59
-26
lines changed

docs/containers.conf.5.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ The default profile name is "container-default".
9696

9797
**base_hosts_file**=""
9898

99-
The hosts entries from the base hosts file are added to the containers hosts
100-
file. This must be either an absolute path or as special values "image" which
101-
uses the hosts file from the container image or "none" which means
102-
no base hosts file is used. The default is "" which will use /etc/hosts.
99+
Base file to create the `/etc/hosts` file inside the container. This must either
100+
be an absolute path to a file on the host system, or one of the following
101+
special flags:
102+
"" Use the host's `/etc/hosts` file (the default)
103+
`none` Do not use a base file (i.e. start with an empty file)
104+
`image` Use the container image's `/etc/hosts` file as base file
103105

104106
**cgroup_conf**=[]
105107

@@ -195,13 +197,25 @@ Pass all host environment variables into the container.
195197

196198
**host_containers_internal_ip**=""
197199

198-
Set the ip for the host.containers.internal entry in the containers /etc/hosts
199-
file. This can be set to "none" to disable adding this entry. By default it
200-
will automatically choose the host ip.
201-
202-
NOTE: When using podman machine this entry will never be added to the containers
203-
hosts file instead the gvproxy dns resolver will resolve this hostname. Therefore
204-
it is not possible to disable the entry in this case.
200+
Set the IP address the container should expect to connect to the host. The IP
201+
address is used by Podman to automatically add the `host.containers.internal`
202+
and `host.docker.internal` hostnames to the container's `/etc/hosts` file. It
203+
is also used for the *host-gateway* flag of Podman's `--add-host` CLI option.
204+
If no IP address is configured (the default), Podman will try to determine it
205+
automatically, but might fail to do so depending on the container's network
206+
setup. Adding these internal hostnames to `/etc/hosts` is silently skipped then.
207+
Set this config to `none` to never add the internal hostnames to `/etc/hosts`.
208+
209+
Note: If Podman is running in a virtual machine using `podman machine` (this
210+
includes Mac and Windows hosts), Podman will silently skip adding the internal
211+
hostnames to `/etc/hosts`, unless an IP address was configured manually. The
212+
internal hostnames are resolved by the gvproxy DNS resolver instead. This config
213+
has no effect on gvproxy. However, since `/etc/hosts` bypasses the DNS resolver,
214+
a manually configured IP address still takes precedence.
215+
216+
Note: This config doesn't affect the actual network setup, it just tells Podman
217+
the IP address it should expect. Configuring an IP address here doesn't ensure
218+
that the container can actually reach the host using this IP address.
205219

206220
**http_proxy**=true
207221

@@ -290,8 +304,10 @@ Options are:
290304

291305
**no_hosts**=false
292306

293-
Create /etc/hosts for the container. By default, container engines manage
294-
/etc/hosts, automatically adding the container's own IP address.
307+
Do not modify the `/etc/hosts` file in the container. Podman assumes control
308+
over the container's `/etc/hosts` file by default; refer to the `--add-host`
309+
CLI option for details. To disable this, either set this config to `true`, or
310+
use the functionally identical `--no-hosts` CLI option.
295311

296312
**oom_score_adj**=0
297313

pkg/config/containers.conf

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@
2727
#
2828
#apparmor_profile = "container-default"
2929

30-
# The hosts entries from the base hosts file are added to the containers hosts
31-
# file. This must be either an absolute path or as special values "image" which
32-
# uses the hosts file from the container image or "none" which means
33-
# no base hosts file is used. The default is "" which will use /etc/hosts.
30+
# Base file to create the `/etc/hosts` file inside the container. This must either
31+
# be an absolute path to a file on the host system, or one of the following
32+
# special flags:
33+
# "" Use the host's `/etc/hosts` file (the default)
34+
# `none` Do not use a base file (i.e. start with an empty file)
35+
# `image` Use the container image's `/etc/hosts` file as base file
3436
#
3537
#base_hosts_file = ""
3638

3739
# List of cgroup_conf entries specifying a list of cgroup files to write to and
3840
# their values. For example `memory.high=1073741824` sets the
3941
# memory.high limit to 1GB.
42+
#
4043
# cgroup_conf = []
4144

4245
# Default way to to create a cgroup namespace for the container
@@ -126,13 +129,25 @@ default_sysctls = [
126129
#
127130
#env_host = false
128131

129-
# Set the ip for the host.containers.internal entry in the containers /etc/hosts
130-
# file. This can be set to "none" to disable adding this entry. By default it
131-
# will automatically choose the host ip.
132-
#
133-
# NOTE: When using podman machine this entry will never be added to the containers
134-
# hosts file instead the gvproxy dns resolver will resolve this hostname. Therefore
135-
# it is not possible to disable the entry in this case.
132+
# Set the IP address the container should expect to connect to the host. The IP
133+
# address is used by Podman to automatically add the `host.containers.internal`
134+
# and `host.docker.internal` hostnames to the container's `/etc/hosts` file. It
135+
# is also used for the *host-gateway* flag of Podman's `--add-host` CLI option.
136+
# If no IP address is configured (the default), Podman will try to determine it
137+
# automatically, but might fail to do so depending on the container's network
138+
# setup. Adding these internal hostnames to `/etc/hosts` is silently skipped then.
139+
# Set this config to `none` to never add the internal hostnames to `/etc/hosts`.
140+
#
141+
# Note: If Podman is running in a virtual machine using `podman machine` (this
142+
# includes Mac and Windows hosts), Podman will silently skip adding the internal
143+
# hostnames to `/etc/hosts`, unless an IP address was configured manually. The
144+
# internal hostnames are resolved by the gvproxy DNS resolver instead. This config
145+
# has no effect on gvproxy. However, since `/etc/hosts` bypasses the DNS resolver,
146+
# a manually configured IP address still takes precedence.
147+
#
148+
# Note: This config doesn't affect the actual network setup, it just tells Podman
149+
# the IP address it should expect. Configuring an IP address here doesn't ensure
150+
# that the container can actually reach the host using this IP address.
136151
#
137152
#host_containers_internal_ip = ""
138153

@@ -221,8 +236,10 @@ default_sysctls = [
221236
#
222237
#netns = "private"
223238

224-
# Create /etc/hosts for the container. By default, container engine manage
225-
# /etc/hosts, automatically adding the container's own IP address.
239+
# Do not modify the `/etc/hosts` file in the container. Podman assumes control
240+
# over the container's `/etc/hosts` file by default; refer to the `--add-host`
241+
# CLI option for details. To disable this, either set this config to `true`, or
242+
# use the functionally identical `--no-hosts` CLI option.
226243
#
227244
#no_hosts = false
228245

0 commit comments

Comments
 (0)