Skip to content

Commit dc878e6

Browse files
authored
ENGDOCS-2376 (#21797)
<!--Delete sections as needed --> ## Description Updates Compose Spec with content in compose-spec/compose-spec#530 Also some freshness of the `ports` attribute ## Related issues or tickets <!-- Related issues, pull requests, or Jira tickets --> ## Reviews <!-- Notes for reviewers here --> <!-- List applicable reviews (optionally @tag reviewers) --> - [ ] Technical review - [ ] Editorial review - [ ] Product review
1 parent d08fe30 commit dc878e6

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

content/reference/compose-file/services.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ platform: linux/arm64/v8
14681468

14691469
> [!NOTE]
14701470
>
1471-
> Port mapping must not be used with `network_mode: host` otherwise a runtime error occurs.
1471+
> Port mapping must not be used with `network_mode: host`. Doing so causes a runtime error because `network_mode: host` already exposes container ports directly to the host network, so port mapping isn’t needed.
14721472

14731473
#### Short syntax
14741474

@@ -1477,20 +1477,20 @@ in the form:
14771477

14781478
`[HOST:]CONTAINER[/PROTOCOL]` where:
14791479

1480-
- `HOST` is `[IP:](port | range)`
1481-
- `CONTAINER` is `port | range`
1482-
- `PROTOCOL` to restrict port to specified protocol. `tcp` and `udp` values are defined by the Specification,
1483-
Compose offers support for platform-specific protocol names.
1480+
- `HOST` is `[IP:](port | range)` (optional). If it is not set, it binds to all network interfaces (`0.0.0.0`).
1481+
- `CONTAINER` is `port | range`.
1482+
- `PROTOCOL` restricts ports to a specified protocol either `tcp` or `upd`(optional). Default is `tcp`.
14841483

1485-
If host IP is not set, it binds to all network interfaces. Ports can be either a single
1486-
value or a range. Host and container must use equivalent ranges.
1484+
Ports can be either a single value or a range. `HOST` and `CONTAINER` must use equivalent ranges.
14871485

1488-
Either specify both ports (`HOST:CONTAINER`), or just the container port. In the latter case,
1486+
You can either specify both ports (`HOST:CONTAINER`), or just the container port. In the latter case,
14891487
the container runtime automatically allocates any unassigned port of the host.
14901488

14911489
`HOST:CONTAINER` should always be specified as a (quoted) string, to avoid conflicts
14921490
with [YAML base-60 float](https://yaml.org/type/float.html).
14931491

1492+
IPv6 addresses can be enclosed in square brackets.
1493+
14941494
Examples:
14951495

14961496
```yml
@@ -1502,26 +1502,28 @@ ports:
15021502
- "49100:22"
15031503
- "8000-9000:80"
15041504
- "127.0.0.1:8001:8001"
1505-
- "127.0.0.1:5000-5010:5000-5010"
1506-
- "6060:6060/udp"
1505+
- "127.0.0.1:5000-5010:5000-5010"
1506+
- "::1:6000:6000"
1507+
- "[::1]:6001:6001"
1508+
- "6060:6060/udp"
15071509
```
15081510

15091511
> [!NOTE]
15101512
>
1511-
> If Host IP mapping is not supported by a container engine, Compose rejects
1513+
> If host IP mapping is not supported by a container engine, Compose rejects
15121514
> the Compose file and ignores the specified host IP.
15131515

15141516
#### Long syntax
15151517

15161518
The long form syntax lets you configure additional fields that can't be
15171519
expressed in the short form.
15181520

1519-
- `target`: The container port
1521+
- `target`: The container port.
15201522
- `published`: The publicly exposed port. It is defined as a string and can be set as a range using syntax `start-end`. It means the actual port is assigned a remaining available port, within the set range.
1521-
- `host_ip`: The Host IP mapping, unspecified means all network interfaces (`0.0.0.0`).
1523+
- `host_ip`: The host IP mapping. If it is not set, it binds to all network interfaces (`0.0.0.0`).
15221524
- `protocol`: The port protocol (`tcp` or `udp`). Defaults to `tcp`.
15231525
- `app_protocol`: The application protocol (TCP/IP level 4 / OSI level 7) this port is used for. This is optional and can be used as a hint for Compose to offer richer behavior for protocols that it understands. Introduced in Docker Compose version [2.26.0](/manuals/compose/releases/release-notes.md#2260).
1524-
- `mode`: `host`: For publishing a host port on each node, or `ingress` for a port to be load balanced. Defaults to `ingress`.
1526+
- `mode`: Specifies how the port is published in a Swarm setup. If set to `host`, it publishes the port on every node in Swarm. If set to `ingress`, it allows load balancing across the nodes in Swarm. Defaults to `ingress`.
15251527
- `name`: A human-readable name for the port, used to document it's usage within the service.
15261528

15271529
```yml

0 commit comments

Comments
 (0)