diff --git a/content/network/drivers/host.md b/content/network/drivers/host.md index dba423e6d1..42769eb49c 100644 --- a/content/network/drivers/host.md +++ b/content/network/drivers/host.md @@ -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) \ No newline at end of file +- Learn about [Macvlan networks](macvlan.md)