Reviewing Network Drivers for Docker
Get to know about reviewing network drivers for Docker.
Network drivers are components that provide networking capabilities between containers. They enable containers to communicate with each other and external networks. They provide the necessary functionality to route network traffic to and from containers. Docker supports multiple network drivers, each with its features and capabilities. Some of these network drivers include the bridge, the host, and the none drivers. We’ll be examining each of them below.
Bridge network driver
The bridge network driver is Docker’s default network driver. When it’s used, virtual networks are created on the host system, which allows containers to bridge communication with each other. Docker assigns IP addresses when containers are created. Those created IPs are what containers use to communicate when bridge network drivers are configured.
We’ll create a bridge network and some containers and try interacting with the containers. We do that through the following below:
Note: Our bridge network is called
bnet
. The first container is calledcontainer1
, while the second is calledcontainer2
.
Create bridge network: We create a bridge network first before the containers, and we do that with the following command:
docker network create bnet
Create containers: We use the following commands to create the containers connecting them with our bridge. The containers use an Nginx image.
# Command to start the first containerdocker run -d --name container1 --network bnet nginx# Command to start the second containerdocker run -d --name container2 --network bnet nginx
Check container status: We check both containers’ status with the following command:
docker ps
Implement interaction within the container and with other containers: We run the following commands to confirm the interaction between containers. To enable interaction between containers, we’ll install the
ping
functionality.
# To get into our containerdocker exec -it <container_id> sh# To install the latest updates within our containerapt-get update# To install pingapt-get install -y iputils-ping# To interact with other containersping <container_id># Cancel ping operation after usage by pressing the key belowctrl+q# To exit the container after running all operations, we type the following commandexit
Note: Try out all commands in the terminal widget below.