Friday, September 11, 2020

What is Docker Network?

 As the name suggests Docker network allows docker containers to communicate with other containers and with the outside world. Docker supports different types of Network configuration depending on the name of the Application / Docker container setup.

Bridge Network
The Bridge network is the default network. The bridge network is used for applications which run in a single Docker container and need to communicate with other containers or host machine. To create a bridge network we need to the argument bridge to the -d switch as follows:
                $ docker network create -d bridge my-bridge

Overlay Network
The Overlay network is used when orchisterating multiple Docker containers. The overlay network connect multiple Docker daemons together and enable swarm services to communicate with each other. We can also use overlay networks to facilitate communication between a swarm service and a standalone container, or between two standalone containers on different Docker daemons.

To create an overlay network we also need the --subnet parameter to specify the network block that Docker will use to assign IP addresses to the containers:

$ docker network create -d overlay --subnet=192.168.10.0/24 my-overlay


Macvlan network
The Macvlan networks allow you to assign a MAC address to a container, making it appear as a physical device on your network. The Docker daemon routes traffic to containers by their MAC addresses.

The macvlan driver is used to connect Docker containers directly to the host network interfaces through layer 2 segmentation. No use of port mapping or network address translation (NAT) is needed and containers can be assigned a public IP address which is accessible from the outside world. Latency in macvlan networks is low since packets are routed directly from Docker host network interface controller to the containers.

To create a macvlan network we need to provide a --gateway parameter to specify the IP address of the gateway for the subnet, and a -o parameter to set driver specific options.

$ docker network create -d macvlan \  --subnet=192.168.35.21/45 \  --gateway=192.168.35.1 \  -o parent=eth0 my-macvlan-net 

Search Flipkart Products:
Flipkart.com

No comments: