Trying to understand the docker networks, Docker creates the following networks automatically:
# docker network ls
NETWORK ID NAME DRIVER SCOPE
67b4afa88032 bridge bridge local
c88f997a2fa7 host host local
1df2947aad7b none null local
I understood that the bridge network represents the docker0 network present in all Docker installations, referring from the link.
Can someone help me in understanding other networks, host and none, If possible with examples.
Bridge network: Bridge is the default network in docker which is also called as docker0. It is the default network that bridges through the NAT firewall to the physical that your host is connected to. But, we don't care about it as all the containers will attach to this network and worked.
If you have any containers running, you could inspect the bridge network as,
...
Note: You can see that automatic IP address assigned to the container which is from the IPAM config subnet.
Host Network: is a special network which skips the virtual networking of docker and attach the container directly to host interface. It's really not recommended but, in certain situations, can improve the performance of high throughput networking and in other, you will loose out of few benefits of containerization.
None Network: is kind of equivalent to having an interface on your machine that's not attched to anything, but we can create our own. The
none
network adds a container to a container-specific network stack. That container lacks a network interface.Docker by default supports 3 networks:
1) None:
This mode will not configure any IP for the container and doesn’t have any access to the external network as well as for other containers. It does have the loopback address and can be used for running batch jobs.
2) Host
In this mode container will share the host’s network stack and all interfaces from the host will be available to the container. The container’s host name will match the host name on the host system
In host and none mode are not configured directly but default bridge network can be configured as well as create your own user-defined bridge networks.
3) Bridge Mode
It is the Docker default networking mode which will enable the connectivity to the other interfaces of the host machine as well as among containers.
Along with these docker provides MACVLAN network which allows to configure multiple Layer 2(MAC) addresses on a single physical interface.
Suppose your docker image support ifconfig, image name is "ubuntu/net"
Then, run docker for host & none: