Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI:DOCS] Update documentation of CLI options affecting /etc/hosts #24043

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

PhrozenByte
Copy link
Contributor

@PhrozenByte PhrozenByte commented Sep 23, 2024

Document the special host-gateway flag of the --add-host option introduced with #19152, mention the special host.containers.internal and host.docker.internal hostnames, and clarify the option's usage in general. Also update resp. cross-reference the related --no-hosts, --hostname, and --name options.

See #19152 and #22653 (comment)

Does this PR introduce a user-facing change?

None

Cc: @Luap99

@mheon
Copy link
Member

mheon commented Sep 23, 2024

One nit, overall LGTM
/approve

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 23, 2024
docs/source/markdown/options/add-host.md Outdated Show resolved Hide resolved
@@ -2,10 +2,14 @@
####> podman build, create, farm build, pod create, run
####> If file is edited, make sure the changes
####> are applicable to all of those.
#### **--add-host**=*host:ip*
#### **--add-host**=*hostname[,hostname[,…]]*:*ip* | *hostname[,hostname[,…]]*:*host-gateway*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the host-gateway need to specified here, makes things more confusing IMO. If you think it is important it should properly be ...=*hostname[;hostname[;…]]*:*<ip>|host-gateway*

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about a similar syntax, too. However, I was unsure and thus checked other Podman options and couldn't find any other Podman option using a simliar syntax (doesn't mean that I might have missed it though). Personally I'd write it as *hostname[;hostname[;…]]*:*ip*|"host-gateway" to indicate that ip is a param and "host-gateway" a fixed string (I also know <> to indicate required params, but that isn't used in Podman either?).

Keeping this consistent is more important though. The problem is that I'm not entirely sure what the most consistent solution is 😅 I'm fine with any variant, just tell me which variant to use, I'll add it then.

About "host-gateway": I feel like that it should be mentioned in the format line, because I believe that the format line should include all possibilities of the option and allow the user to fully understand the option without reading the description. But I'm fine with not mentioning it, too. Basically I'm fine with anything 😄 I've removed it for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not to sure either, yes the syntax is not very consistent across all our man pages.
If you like to keep host-gateway in the format line that is fine for me.

Although I guess the description could also need some more explaining what host-gateway is, i.e. a ip address that can be used to connect from the container to the host.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the suggested *hostname[;hostname[;…]]*:*ip*|"host-gateway"? If that syntax is okay, I'd suggest using that.


Not sure how to further elaborate on host-gateway though. Right now we have this:

Instead of an IP address the special flag host-gateway can be given that resolves to an IP address the container can use to connect to the host. Podman will automatically add the host.containers.internal and host.docker.internal hostnames using the host-gateway address, unless the --no-hosts option is given.

We could add more details about how Podman chooses that IP address, but this fundamentally depends on the network mode used and even some other options as well, like if IPv4 is disabled (I assume that host-gateway resolves to an IPv6 address then?). I'm not entirely sure whether such details add much clarification.

I just checked Docker's docs on this, see https://docs.docker.com/reference/cli/docker/container/run/#add-host. They describe the option as follows:

The --add-host flag supports a special host-gateway value that resolves to the internal IP address of the host. This is useful when you want containers to connect to services running on the host machine.

It's conventional to use host.docker.internal as the hostname referring to host-gateway. Docker Desktop automatically resolves this hostname, see Explore networking features.

I feel like this is all mentioned already. Suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the suggested hostname[;hostname[;…]]:ip|"host-gateway"? If that syntax is okay, I'd suggest using that.

Works for me.


For the other point it is rather complicated, first of all there is no guarantee that host.containers.internal will be added. Depending on your host setup we might not be able to find a free host ip for this so I feel like it is important to mention that the entry might not be set.
With podman machine it is even more complciated as we do not add it to /etc/hosts and let the gvproxy dns resolver resolve the real host ip as podman would use the VM ip otherwise.

And this should likely point to host_containers_internal_ip option from containers.conf because users can overwrite the behavior there or set a fixed ip if they like.

So overall I think something like this:

Unless disabled in via *host_containers_internal_ip* option  in *containers.conf* Podman will add the `host.containers.internal` and `host.docker.internal` name by default with an ip pointing to the host. If Podman cannot figure out a suitable ip address it may not add this entry. In order to use a different name it is possible to use `--add-host <name>:host-gateway` and then it will use the same ip in place of host-gateway automatically, however if it failed to find a suitable ip in that case Podman will return an error instead and not silently skip the entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. See updated suggestion.

I skipped mentioning that one can force Podman to add the internal hostnames using --add-host. I rather added a general note that one can use --add-host to overwrite any automatically added entries (I actually use that for --hostname), therefore implying that this is also true for these internal hostnames, even though not specifically mentioning it because I assume this is very rarely used for that.

Since this yields some cross references I decided to not just update --add-host, but --no-hosts, --hostname, and --name as well. This should unify them and hopefully constitute a definitive documentation of Podman's /etc/hosts file. Did I miss something?

I assumed that host_containers_internal_ip also overwrites host-gateway of --add-host, not just the internal hostnames. Is that correct?

Open question: I checked the docs of the host_containers_internal_ip config and one can apparently set it to 'none' to disable adding the internal hostnames by default. Does setting host_containers_internal_ip="none" also affect host-gateway of --add-host? If yes, how? I assumed that it should have no effect, but is that actually true?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that host_containers_internal_ip also overwrites host-gateway of --add-host, not just the internal hostnames. Is that correct?

Yes

Does setting host_containers_internal_ip="none" also affect host-gateway of --add-host? If yes, how? I assumed that it should have no effect, but is that actually true?

It will cause an error and not work but this is more of a how the code works today and I am not opposed to changing this in the future if anyone needs that.

@PhrozenByte PhrozenByte force-pushed the docs-add-host-gateway branch 2 times, most recently from 9cb3633 to 1eb7ba6 Compare September 24, 2024 15:13
@PhrozenByte PhrozenByte changed the title [CI:DOCS] Update documentation of --add-host CLI option [CI:DOCS] Update documentation of CLI options affecting /etc/hosts Sep 24, 2024
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you

@PhrozenByte
Copy link
Contributor Author

Since we've changed a lot since your initial review @mheon, you might wanna take another look. Thank you! 👍

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man page check complains about

values must be space-separated: '=*hostname[;hostname[;…]]*:*ip*|"host-gateway"'

@edsantiago Do you know hoe the format string should be changed here to make the check happy?

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! A few suggestions inline. None of them are firm, i.e., please feel free to find your own alternatives (within grammatical correctness of course)

docs/source/markdown/options/add-host.md Outdated Show resolved Hide resolved
docs/source/markdown/options/add-host.md Outdated Show resolved Hide resolved
docs/source/markdown/options/add-host.md Outdated Show resolved Hide resolved
docs/source/markdown/options/hostname.pod.md Outdated Show resolved Hide resolved
Document the special *host-gateway* flag introduced with containers#19152, mention the special `host.containers.internal` and `host.docker.internal` hostnames, and clarify the option's usage in general.

Signed-off-by: Daniel Rudolf <[email protected]>
…options

Update the docs to properly cross-reference the `--add-host` option.

Signed-off-by: Daniel Rudolf <[email protected]>
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@PhrozenByte
Copy link
Contributor Author

Thank you @edsantiago, all fixed 👍

Looks like that the docs complaint is gone, but CI is failing for some other reason now 🙈 No idea what's going on there… Can't even find the logs 😕

I think my only recommendation is to drop everything after pipe, and trust that the paragraph starting on line 16 will be clear enough.

Too bad that we can't include it, but I agree that repeating the whole option just for "host-gateway" isn't feasible... So we'll leave it.

Could I suggest changing the Unicode ellipsis to three ASCII dots?

I was a little confused about that request at first because Unicode ellipsis are used all over the parsed docs, but I just noticed that they are apparently added later when parsing the source files… 😏

@edsantiago
Copy link
Member

CI is fine! The blue-robot things are always (well, very often) red. We ignore those. The CI that matters is green. Re-reviewing now.

Copy link
Contributor

openshift-ci bot commented Sep 25, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: edsantiago, Luap99, mheon, PhrozenByte

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Luap99,edsantiago,mheon]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@edsantiago
Copy link
Member

Too bad that we can't include ip|host-gateway

At the risk of beating a dead horse, one way to do that might be: **--add-host**=*hostname[;hostname[;...]]*:*IP-OR-KEYWORD* and then change the wording to something like "IP-OR-KEYWORD is an IP address or the special keyword "...."` I'll leave it up to you whether you want to go that route.

LGTM, will leave final approval to @mheon per above request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants