Docker Container (C50) – Host Networking vs Bridge Networking

Resolution

Host Networking vs Bridge Networking

Bridge mode is the default mode of networking enabling great flexibility to shift container workloads between hosts easily. The container uses an automatically assigned private IP address (Docker normally takes care of DNS too). Containers on the same bridge can talk to each other.

In this mode you can view the IP address of the primary network interface of the container:

[email protected]:~/support-lab-cmp-01$ sudo docker exec -it ba2c53b58e62 /bin/bash
[email protected]:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.19.0.2  netmask 255.255.0.0  broadcast 172.19.255.255
        ether 02:42:ac:13:00:02  txqueuelen 0  (Ethernet)
        RX packets 315352  bytes 28212974 (26.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 314701  bytes 82837363 (78.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

As well as the bridge interface of the host:

 

[email protected]:~$ sudo ip addr
...
37: br-122b5f8b8d14: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:87:c1:de:c2 brd ff:ff:ff:ff:ff:ff
    inet 172.19.0.1/16 brd 172.19.255.255 scope global br-122b5f8b8d14
       valid_lft forever preferred_lft forever
    inet6 fe80::42:87ff:fec1:dec2/64 scope link
       valid_lft forever preferred_lft forever
...

 

 

 

Host mode means the container’s network stack is not isolated from the host’s. This mode is only available on Linux.

Verifying networking mode in a running container

 

docker container inspect <pathview-cmp container id> | grep "NetworkMode"

Bridge Networking result:
$ sudo docker inspect ba2c53b58e62 | grep "NetworkMode"
            "NetworkMode": "support-lab-cmp-01_default",

Host Networking result:
$ sudo docker inspect ba2c53b58e62 | grep "NetworkMode"
						"NetworkMode": "host",