#
HOST Networking in Docker
This tutorial explains host networking mode in Docker.
Here is the picture which shows how host networking
is working:
Here are the main things to retain:
- the containers created with
--network host
use the networking namespace of the host.
Info
The network namespace
is a logical copy of the network stack from the host system.
Network namespaces are useful for setting up containers or virtual environments.
Each namespace has its own IP addresses, network interfaces, routing tables, and so forth.
- make the programs inside the Docker container look like they are running on the host itself, from the perspective of the network.
For instance, in the example above, you can access the HTTP Server from the container 2, from the host, using http://localhost:8081 as the HTTP server is running directly on the host machine.
you no longer have to maps the container ports to the host ports, but you have to set up ports which are not in conflict with other containers or with other services which run on the host machine.
You can start a Docker container in host networking mode as in the following example:
docker run -d --network host httpd:latest
- 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.