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 <[email protected]>
  • Loading branch information
robmry committed Nov 23, 2023
1 parent 478928e commit c1b2244
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
22 changes: 20 additions & 2 deletions 05-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -850,12 +850,28 @@ 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, for example:

```yml
extra_hosts:
- "myhostv6=[::1]"
```

The separator `=` is preferred, but `:` can also 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 +881,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 +890,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
18 changes: 17 additions & 1 deletion build.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,25 @@ 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, for example:

```yml
extra_hosts:
- "myhostv6=[::1]"
```

The separator `=` is preferred, but `:` can also 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 All @@ -301,6 +316,7 @@ configuration, which means for Linux `/etc/hosts` will get extra lines:
```
162.242.195.82 somehost
50.31.209.229 otherhost
::1 myhostv6
```

### isolation
Expand Down
22 changes: 20 additions & 2 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1063,12 +1063,28 @@ 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, for example:

```yml
extra_hosts:
- "myhostv6=[::1]"
```

The separator `=` is preferred, but `:` can also 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 +1094,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 +1103,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 c1b2244

Please sign in to comment.