Add info about host network support in DD 4.29 (#19654)

* Add info about host network support in DD 4.29

* Review suggestions

* Apply suggestions from code review

Co-authored-by: Allie Sadler <102604716+aevesdocker@users.noreply.github.com>

* Apply review suggestions

* Remove text saying that host networking is a paid feature

---------

Co-authored-by: Allie Sadler <102604716+aevesdocker@users.noreply.github.com>
This commit is contained in:
Andreas Heck 2024-04-08 17:24:03 +02:00 committed by GitHub
parent e1414ca78f
commit 64f176ba56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 54 additions and 3 deletions

View File

@ -31,8 +31,7 @@ Host mode networking can be useful for the following use cases:
This is because it doesn't require network address translation (NAT), and no "userland-proxy" is created for each port.
The host networking driver only works on Linux hosts, and is not supported on
Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.
The host networking driver only works on Linux hosts, but is available as a Beta feature, on Docker Desktop version 4.29 and later.
You can also use a `host` network for a swarm service, by passing `--network host`
to the `docker service create` command. In this case, control traffic (traffic
@ -42,10 +41,62 @@ daemon's host network and ports. This creates some extra limitations. For instan
if a service container binds to port 80, only one service container can run on a
given swarm node.
## Docker Desktop
Host networking is also supported on Docker Desktop version 4.29 and later for Mac,
Windows, and Linux as a beta feature.
This feature works in both directions. This means you can
access a server that is running in a container from your host and you can access
servers running on your host from any container that is started with host
networking enabled. TCP as well as UDP are supported as communication protocols.
### Examples
The following command starts netcat in a container that listens on port `8000`:
```console
$ docker run --rm -it --net=host nicolaka/netshoot nc -lkv 0.0.0.0 8000
```
Port `8000` will then be available on the host and you can connect to it with the following
command from another terminal:
```console
$ nc localhost 8000
```
What you type in here will then appear on the terminal where the container is
running.
To access a service running on the host from the container, you can start a container with
host networking enabled with this command:
```console
$ docker run --rm -it --net=host nicolaka/netshoot
```
If you then want to access a service on your host from the container (in this
example a web server running on port `80`), you can do it like this:
```console
$ nc localhost 80
```
### Limitations
The host network feature of Docker Desktop works on layer 4. This means that
unlike with Docker on Linux, network protocols that operate below TCP or UDP are
not supported.
Also, the feature doesn't work with Enhanced Container Isolation enabled, since
isolating your containers from the host and allowing them access to the host
network contradict each other.
## Next steps
- Go through the [host networking tutorial](../network-tutorial-host.md)
- Learn about [networking from the container's point of view](../index.md)
- Learn about [bridge networks](bridge.md)
- Learn about [overlay networks](overlay.md)
- Learn about [Macvlan networks](macvlan.md)
- Learn about [Macvlan networks](macvlan.md)