Skip to content

Commit ea7e170

Browse files
committed
Address review comments.
- Note that publishing a port to an external host address does not restrict access to the interface with that address. - Fix some formatting. Signed-off-by: Rob Murray <[email protected]>
1 parent 6e23653 commit ea7e170

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

content/manuals/engine/network/port-publishing.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Here are some examples:
4444
> the outside world as well.
4545
>
4646
> If you include the localhost IP address (`127.0.0.1`, or `::1`) with the
47-
> publish flag, only the Docker host.
47+
> publish flag, only the Docker host can access the published container port.
4848
>
4949
> ```console
5050
> $ docker run -p 127.0.0.1:8080:80 -p '[::1]:8080:80' nginx
@@ -138,18 +138,31 @@ rules are still set up so that only published container ports are accessible.
138138
Outgoing packets from the container will use the container's address,
139139
not a host address.
140140

141-
In `nat` mode, when a port is published to a specific host address, that
142-
port is only accessible via the host interface with that address. So,
143-
for example, publishing a port to an address on the loopback interface
144-
means remote hosts cannot access it.
145-
146-
However, using direct routing, published container ports are always
147-
accessible from remote hosts, unless the Docker host's firewall has
148-
additional restrictions. Hosts on the local layer-2 network can set up
141+
To access a published port in a `routed` network, remote hosts must have
142+
a route to the container network via an external address on the Docker
143+
host ("direct routing"). Hosts on the local layer-2 network can set up
149144
direct routing without needing any additional network configuration.
150145
Hosts outside the local network can only use direct routing to the
151146
container if the network's routers are configured to enable it.
152147

148+
In a `nat` mode network, publishing a port to an address on the loopback
149+
interface means remote hosts cannot access it. Other published container
150+
ports in `routed` and `nat` networks are always accessible from remote
151+
hosts using direct routing, unless the Docker host's firewall has additional
152+
restrictions.
153+
154+
> [!NOTE]
155+
>
156+
> When a port is published to a specific host address in `nat` mode, if
157+
> IP forwarding is enabled on the Docker host, the published port can be
158+
> accessed via other host interfaces using direct routing to the host
159+
> address.
160+
>
161+
> For example, a Docker host with IP forwarding enabled has two NICs with
162+
> addresses `192.168.100.10/24` and `10.0.0.10/24`.
163+
> When a port is published to `192.168.100.10`, a host in the `10.0.0.0/24`
164+
> subnet can access that port by routing to `192.168.100.10` via `10.0.0.10`.
165+
153166
In `nat-unprotected` mode, unpublished container ports are also
154167
accessible using direct routing, no port filtering rules are set up.
155168
This mode is included for compatibility with legacy default behaviour.
@@ -269,11 +282,12 @@ For example:
269282

270283
> [!NOTE]
271284
>
272-
> - Setting the default binding address to `::` means port bindings with no host
273-
> address specified will work for any IPv6 address on the host. But, `0.0.0.0`
274-
> means any IPv4 or IPv6 address.
275-
> - Changing the default bind address doesn't have any effect on Swarm services.
276-
> Swarm services are always exposed on the `0.0.0.0` network interface.
285+
> Setting the default binding address to `::` means port bindings with no host
286+
> address specified will work for any IPv6 address on the host. But, `0.0.0.0`
287+
> means any IPv4 or IPv6 address.
288+
>
289+
> Changing the default bind address doesn't have any effect on Swarm services.
290+
> Swarm services are always exposed on the `0.0.0.0` network interface.
277291
278292
### Default bridge
279293

0 commit comments

Comments
 (0)