Skip to content

Commit

Permalink
Permit '=' separator and '[ipv6]' in 'extra_hosts'
Browse files Browse the repository at this point in the history
Fixes docker/cli#4648

Update the 'extra_hosts' element to align with changes in 'docker/cli'
and 'docker/buildx' that 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:

  extra_hosts:
    - "somehost=162.242.195.82"
    - "myhostv6=::1"
    - "anotherhostv6=[2001:4860:4860::8888]"

Signed-off-by: Rob Murray <rob.murray@docker.com>
  • Loading branch information
robmry committed Nov 22, 2023
1 parent 478928e commit 79b07fc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
15 changes: 14 additions & 1 deletion 05-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -850,12 +850,23 @@ external_links:
`extra_hosts` adds hostname mappings to the container network interface configuration (`/etc/hosts` for Linux).

### Short syntax
Short syntax uses plain strings in a list. Values must set hostname and IP address for additional hosts in the form of `HOSTNAME:IP`.
Short syntax uses plain strings in a list. Values must set hostname and IP address for additional hosts in the form of `HOSTNAME=IP`.

```yml
extra_hosts:
- "somehost=162.242.195.82"
- "otherhost=50.31.209.229"
- "myhostv6=::1"
```

IPv6 addresses can be enclosed in square brackets and, for backward
compatibility, the separator `:` can be used. For example:

```yml
extra_hosts:
- "somehost:162.242.195.82"
- "otherhost:50.31.209.229"
- "myhostv6:[::1]"
```

### Long syntax
Expand All @@ -865,6 +876,7 @@ Alternatively, `extra_hosts` can be set as a mapping between hostname(s) and IP(
extra_hosts:
somehost: "162.242.195.82"
otherhost: "50.31.209.229"
myhostv6: "::1"
```

Compose creates a matching entry with the IP address and hostname in the container's network
Expand All @@ -873,6 +885,7 @@ configuration, which means for Linux `/etc/hosts` get extra lines:
```
162.242.195.82 somehost
50.31.209.229 otherhost
::1 myhostv6
```

## group_add
Expand Down
9 changes: 9 additions & 0 deletions build.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,19 @@ Illustrative examples of how this is used in Buildx can be found

`extra_hosts` adds hostname mappings at build-time. Use the same syntax as [extra_hosts](05-services.md#extra_hosts).

```yml
extra_hosts:
- "somehost=162.242.195.82"
- "otherhost=50.31.209.229"
- "myhostv6=::1"
```
IPv6 addresses can be enclosed in square brackets, and the separator `:` can be used. For example:

```yml
extra_hosts:
- "somehost:162.242.195.82"
- "otherhost:50.31.209.229"
- "myhostv6:[::1]"
```

Compose creates matching entry with the IP address and hostname in the container's network
Expand Down
15 changes: 14 additions & 1 deletion spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1063,12 +1063,23 @@ external_links:
`extra_hosts` adds hostname mappings to the container network interface configuration (`/etc/hosts` for Linux).

### Short syntax
Short syntax uses plain strings in a list. Values must set hostname and IP address for additional hosts in the form of `HOSTNAME:IP`.
Short syntax uses plain strings in a list. Values must set hostname and IP address for additional hosts in the form of `HOSTNAME=IP`.

```yml
extra_hosts:
- "somehost=162.242.195.82"
- "otherhost=50.31.209.229"
- "myhostv6=::1"
```

IPv6 addresses can be enclosed in square brackets and, for backward
compatibility, the separator `:` can be used. For example:

```yml
extra_hosts:
- "somehost:162.242.195.82"
- "otherhost:50.31.209.229"
- "myhostv6:[::1]"
```

### Long syntax
Expand All @@ -1078,6 +1089,7 @@ Alternatively, `extra_hosts` can be set as a mapping between hostname(s) and IP(
extra_hosts:
somehost: "162.242.195.82"
otherhost: "50.31.209.229"
myhostv6: "::1"
```

Compose creates a matching entry with the IP address and hostname in the container's network
Expand All @@ -1086,6 +1098,7 @@ configuration, which means for Linux `/etc/hosts` get extra lines:
```
162.242.195.82 somehost
50.31.209.229 otherhost
::1 myhostv6
```

## group_add
Expand Down

0 comments on commit 79b07fc

Please sign in to comment.