Permit '=' separator and '[ipv6]' in --add-host#4663
Conversation
249cc14 to
0cecb05
Compare
thaJeztah
left a comment
There was a problem hiding this comment.
just some quick comments from my comments phone
|
|
||
| // 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.
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.
Ah, yes - good idea! Will do, thank you.
| $ 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.
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)
0cecb05 to
cf631cd
Compare
dvdksn
left a comment
There was a problem hiding this comment.
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 |
thaJeztah
left a comment
There was a problem hiding this comment.
Thanks! I left some comments; non-critical, but some would probably be good to address before merging (happy to hear your thoughts!)
|
|
||
| **--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.
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.
Yes, will do. (Also makes it consistent with other text that I'd already fixed.)
|
|
||
| **--add-host**=[] | ||
| Add a custom host-to-IP mapping (host:ip) | ||
| Add a custom host-to-IP mapping (host:ip, or host=ip) |
| 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.
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 alpineI'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 msThe 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-hostnameI 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-hostnameThere was a problem hiding this comment.
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.
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.
| // hostname:127.0.0.1 | ||
| // hostname:::1 | ||
| // hostname=::1 | ||
| // hostname:[::1] |
There was a problem hiding this comment.
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.
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.
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-hostnameThere was a problem hiding this comment.
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.
| 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.
While we're updating these, perhaps also update the example hostnames (per my other comment)
| }, | ||
| { | ||
| doc: "Missing address, eq sep", | ||
| input: `missing.address.eq=`, |
There was a problem hiding this comment.
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.
Ah, yes - that'd be better, will do.
59df3e9 to
974b5d4
Compare
|
Looks like this needs a rebase 🙈 |
974b5d4 to
3068630
Compare
|
|
||
| // 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)") |
There was a problem hiding this comment.
@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.
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
thaJeztah
left a comment
There was a problem hiding this comment.
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 runcommand sets up a/etc/hostsentry as expected when using '=' and brackets ...But
docker inspectstill shows the option with a ':' separator and no brackets ...The same formats work for legacy
docker build,buildxneeds a separate change ...- Description for the changelog
Permit '=' separator and '[ipv6]' in --add-host