-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 #4663
Conversation
249cc14
to
0cecb05
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.
just some quick comments from my comments phone
cli/command/container/opts.go
Outdated
@@ -210,7 +210,7 @@ func addFlags(flags *pflag.FlagSet) *containerOptions { | |||
flags.SetAnnotation("cgroupns", "version", []string{"1.41"}) | |||
|
|||
// Network and port publishing flag | |||
flags.Var(&copts.extraHosts, "add-host", "Add a custom host-to-IP mapping (host:ip)") | |||
flags.Var(&copts.extraHosts, "add-host", "Add a custom host-to-IP mapping (host:ip, or 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 slightly leaning towards "soft deprecating" the old format, and not advertising it too prominent.
In the docs, we could still make a mention of the old format (for users who are running an older version of the cli)
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 - good idea! Will do, thank you.
docs/reference/commandline/build.md
Outdated
@@ -462,6 +462,12 @@ more `--add-host` flags. This example adds a static address for a host named | |||
$ docker build --add-host docker:10.180.0.1 . | |||
``` | |||
|
|||
For IPv6 addresses, the equivalent `host=ip` form may be clearer, for example: |
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.
Related to my other comment; we can use the new format as default for the example, and make a mention of the old format.
(also /cc @dvdksn for suggestions)
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.
0cecb05
to
cf631cd
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.
looks good, a couple suggestions
cf631cd
to
59df3e9
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #4663 +/- ##
==========================================
+ Coverage 59.75% 59.77% +0.01%
==========================================
Files 287 287
Lines 24821 24830 +9
==========================================
+ Hits 14832 14841 +9
Misses 9103 9103
Partials 886 886 |
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.
docs lgtm 👍🏻
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.
Thanks! I left some comments; non-critical, but some would probably be good to address before merging (happy to hear your thoughts!)
man/docker-build.1.md
Outdated
@@ -78,10 +78,10 @@ set as the **URL**, the repository is cloned locally and then sent as the contex | |||
layers in tact, and one for the squashed version. | |||
|
|||
**--add-host** [] | |||
Add a custom host-to-IP mapping (host:ip) | |||
Add a custom host-to-IP mapping (host:ip, or 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.
Micro-nit; perhaps swap the order to put the preference on =
;
Add a custom host-to-IP mapping (host=ip, or 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.
Yes, will do. (Also makes it consistent with other text that I'd already fixed.)
man/docker-run.1.md
Outdated
@@ -121,10 +121,10 @@ executables expect) and pass along signals. The **-a** option can be set for | |||
each of stdin, stdout, and stderr. | |||
|
|||
**--add-host**=[] | |||
Add a custom host-to-IP mapping (host:ip) | |||
Add a custom host-to-IP mapping (host:ip, or 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.
Same here
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.
Will do.
docs/reference/commandline/run.md
Outdated
The `--add-host` flag also accepts a `:` separator, for example: | ||
|
||
```console | ||
$ docker run --add-host=docker:93.184.216.34 --rm -it alpine |
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.
For examples, I try to use names that help identify they're "custom" values (and for illustrative purpose). Using docker
(or hostname
as was used elsewhere) could be confused for "docker" being some special value.
Something like my-hostname
could perhaps work;
$ docker run --add-host=my-hostname:93.184.216.34 --rm -it alpine
I'm curious where the 93.184.216.34
address came from; it
It's also good to make an example "do" something. In this case, we want to illustrate that adding the hostname allows the hostname to be resolved inside the container. I'm curious where the 93.184.216.34
IP-address came from, but if we want to be sure ping
works, perhaps we should use a well-known IP-address, e.g. 8.8.8.8
;
$ docker run --add-host=my-hostname:8.8.8.8 --rm alpine ping -c1 my-hostname
PING my-hostname (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=63 time=14.995 ms
--- my-hostname ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 14.995/14.995/14.995 ms
The advantage of ping
of course is that (most) users would understand what we're doing. Alternatively (if we don't want to depend on networking, and only illustrate the actual effect), we could show that the entry was added to /etc/hosts
inside the container (but not sure if that's to be considered too much an implementation details);
$ docker run --add-host=my-hostname:8.8.8.8 --rm alpine sh -c 'cat /etc/hosts | grep my-hostname'
8.8.8.8 my-hostname
I considered nslookup
as alternative, but 🙈 of course that doesn't work with /etc/hosts
, so we'd need something like getent
, which probably isn't ideal (not as widely used; at least I had to quickly lookup the right way to use it 😂)
$ docker run --add-host=my-hostname:8.8.8.8 --rm alpine getent ahosts my-hostname
8.8.8.8 STREAM my-hostname
8.8.8.8 DGRAM my-hostname
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.
Oh! Before I forget (and probably not needed for these examples); if we use example domains in our docs; always make sure to use one of the designated domains for that purpose, such as *.example.com
, *.example.org
(https://www.rfc-editor.org/rfc/rfc6761.html).
(We've had cases where we used some (assumed) made-up domain, which... was in active use 😬)
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.
docker:93.184.216.34
was already used in the ping example (the address was introduced in 47ba76a ) ... so I kept it, but something like my-hostname:8.8.8.8
looks better, I'll change it.
"ping" seems like a nice simple/clear example, and with 8.8.8.8
it should normally work, so I'll keep it.
opts/hosts.go
Outdated
// hostname:127.0.0.1 | ||
// hostname:::1 | ||
// hostname=::1 | ||
// hostname:[::1] |
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.
See my other comment; perhaps use my-hostname
or something similar, to prevent hostname
being confused for a special keyword.
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.
Makes sense - will do!
// ValidateIPAddress returns the address in canonical form (for example, | ||
// 0:0:0:0:0:0:0:1 -> ::1). But, stick with the original form, to avoid | ||
// surprising a user who's expecting to see the address they supplied in the | ||
// output of 'docker inspect' or '/etc/hosts'. | ||
if _, err := ValidateIPAddress(v); err != nil { |
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.
Not for this PR, but still considering using the normalised variant; that would potentially avoid duplicates;
docker run --add-host=my-hostname:0:0:0:0:0:0:0:1 --add-host=my-hostname:::1 --rm alpine sh -c 'cat /etc/hosts | grep my-hostname'
0:0:0:0:0:0:0:1 my-hostname
::1 my-hostname
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, I hadn't thought about duplicates - was more worried about second-guessing the user. I think only the last entry will be used if there are duplicates. I suppose we could use the canonical form to check for duplicates internally, and preserve the user's address in the file.
docs/reference/commandline/build.md
Outdated
or more `--add-host` flags. This example adds static addresses for hosts named | ||
`docker` and `dockerv6`: | ||
|
||
```console | ||
$ docker build --add-host docker:10.180.0.1 . | ||
$ docker build --add-host docker=10.180.0.1 --add-host dockerv6=2001:db8::33 . |
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.
While we're updating these, perhaps also update the example hostnames (per my other 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.
Will do.
opts/hosts_test.go
Outdated
}, | ||
{ | ||
doc: "Missing address, eq sep", | ||
input: `missing.address.eq=`, |
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.
For tests, I also tend to use the special domain-names (example.com
, example.org
, and/or the .invalid
TLDs) where possible of course.
Unlikely to happen for a unit-test, but I've had some test-cases in other repositories happily sending requests to some random domains that actually existed 🙈
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 - that'd be better, will do.
59df3e9
to
974b5d4
Compare
Looks like this needs a rebase 🙈 |
974b5d4
to
3068630
Compare
cli/command/container/opts.go
Outdated
flags.Var(&copts.extraHosts, "add-host", "Add a custom host-to-IP mapping (host:ip)") | ||
flags.Var(&copts.extraHosts, "add-host", "Add a custom host-to-IP mapping (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.
@robmry as we're still debating the "race condition" between buildx and the cli; perhaps we should consider changing the flag description back to host:ip
, and update it to the new format for v26 (release after v25) WDYT?
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 - sure, I'll do that now ...
Fixes docker#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=my-hostname:127.0.0.1 --add-host=my-hostname:::1 --add-host=my-hostname=::1 --add-host=my-hostname:[::1] To avoid compatibility problems, the CLI will replace an '=' separator with ':', and strip brackets, before sending the request to the API. Signed-off-by: Rob Murray <[email protected]>
3068630
to
a682b8e
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
let me do a quick check if consensus was reached on including the new format in buildx 0.12.x
Let's bring this one in; looks like buildx will get this format in v0.13.0, so there will be some period where they don't match, but don't think there's a good way around that (without docker/buildx#2149) |
Fixes #4648
- 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
To avoid compatibility problems, the CLI will replace an '=' separator with ':', and strip brackets, before sending the request to the API.
- How to verify it
New unit tests pass.
The
docker run
command sets up a/etc/hosts
entry as expected when using '=' and brackets ...But
docker inspect
still shows the option with a ':' separator and no brackets ...The same formats work for legacy
docker build
,buildx
needs a separate change ...- Description for the changelog
Permit '=' separator and '[ipv6]' in --add-host