-
Notifications
You must be signed in to change notification settings - Fork 496
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
Permit '=' separator and '[ipv6]' in --add-host #2121
Conversation
f394488
to
75740c4
Compare
host, ip, ok := strings.Cut(h, "=") | ||
if !ok { | ||
host, ip, ok = strings.Cut(h, ":") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update the reference docs in
Line 489 in cb37886
flags.StringSliceVar(&options.extraHosts, "add-host", []string{}, `Add a custom host-to-IP mapping (format: "host:ip")`) |
Guess it should be ... (format: "host=ip")
if this format is the preferred one now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes - will do! Thank you.
75740c4
to
f8196c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The changes for CLI and buildx are done - but docker-compose has an "extra_hosts" option that'll need the same treatment. |
f8196c8
to
28cb12d
Compare
Updated to use domain ".invalid" in unit tests - as per @thaJeztah's comment on the CLI review, docker/cli#4663 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I added a cherry-pick label for consideration (so that buildx and cli will align on accepted formats) |
docs/reference/buildx_build.md
Outdated
@@ -15,7 +15,7 @@ Start a build | |||
|
|||
| Name | Type | Default | Description | | |||
|:-------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------|:----------|:----------------------------------------------------------------------------------------------------| | |||
| [`--add-host`](https://docs.docker.com/engine/reference/commandline/build/#add-host) | `stringSlice` | | Add a custom host-to-IP mapping (format: `host:ip`) | | |||
| [`--add-host`](https://docs.docker.com/engine/reference/commandline/build/#add-host) | `stringSlice` | | Add a custom host-to-IP mapping (format: `host=ip`) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we should just switch the formatting in docs as it takes time for people to upgrade to the latest versions. Doesn't look like the old formatting is deprecated as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I see what you mean - the online docs aren't very version-specific.
This part of the ".md" is generated from the flags.StringSliceVar() text. We could put both in there with an "or", but that may not really help to make it obvious that the :
is for backward compatibility - and we probably don't want an essay in there. Earlier comments have been about preferring ("soft-deprecating") the colon separator.
On the other hand, the "--add-host" in the first column here is a link to the cli/build docs, here it is in my branch ...
And the modified version of the page it'll link to is here ...
It says ...
You can wrap an IPv6 address in square brackets.
=
and:
are both valid separators. Both formats in the following example are valid:
... perhaps we should make it clear there that the :
is for backward compatibility?
@dvdksn - any suggestions?
commands/build.go
Outdated
@@ -486,7 +486,7 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debug.D | |||
|
|||
flags := cmd.Flags() | |||
|
|||
flags.StringSliceVar(&options.extraHosts, "add-host", []string{}, `Add a custom host-to-IP mapping (format: "host:ip")`) | |||
flags.StringSliceVar(&options.extraHosts, "add-host", []string{}, `Add a custom host-to-IP mapping (format: "host=ip")`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could keep the example as :
here, until we officially deprecate that separator. That would give users time to upgrade to later versions which would support both syntaxes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do ...
@crazy-max - this will undo the earlier change for your #2121 (comment) - but I think it makes sense given #2121 (comment) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes agree let's keep :
for now
Fixes docker/cli#4648 Make it easier to specify IPv6 addresses in the '--add-host' option by permitting 'host=ip' in addition to 'host:ip', and allowing square brackets around the address. For example: --add-host=hostname:127.0.0.1 --add-host=hostname:::1 --add-host=hostname=::1 --add-host=hostname=[::1] Signed-off-by: Rob Murray <[email protected]>
28cb12d
to
eeeff1c
Compare
--add-host
option cli#4648--add-host
option cli#4648 (comment)- What I did
Make it easier to specify IPv6 addresses in the '--add-host' option by permitting 'host=ip' in addition to 'host:ip', and allowing square brackets around the address.
For example:
- How I did it
Updated the function that converts from
--add-host
format to buildx's csv format, stripping brackets from the address.This pull request is equivalent to one in
docker/cli
, fordocker run
and legacy builds.- How to verify it
New unit tests pass. And ...
- Description for the changelog
Permit '=' separator and '[ipv6]' in --add-host