Open In App

How to use Docker Default Bridge Networking?

Improve
Improve
Like Article
Like
Save
Share
Report

Docker allows you to create dedicated channels between multiple Docker Containers to create a network of Containers that can share files and other resources. This is called Docker Networking. You can create Docker Networks with various kinds of Network Drivers which include Bridge drivers, McVLAN drivers, etc. By default, if you do not mention a driver while creating a network, it automatically chooses the default bridge driver. Bridge drivers are single-host networking drivers and hence their scope is limited to local.

In this article, we are going to discuss how to create, manage, and use Docker Bridge Networks. For this, you would need a Linux-based Host machine with access to Docker. Without any further ado, let’s dive deep into Docker Bridged Networking.

Bridge Network Driver

The bridge is a default network where containers will be created by default if you are not mentioned any network while creating. The containers which are deployed in the same network can talk to each other the containers which are not in the same network can’t communicate with each other without proper mentions and permissions. While creating a docker network if you are not going to create or mention any network while creating a container. To list the networks in docker you can use the following command.

docker network ls

Types of Docker Networks

There are three main default networks as mentioned following and also to know more about Docker networking refer to Docker Networking.

  1. Bridge(default)
  2. Host
  3. None/Null

Connect a Container To a User-Defined Bridge

If containers are created in a default bridge network. Communication will happen only with the IP Address of the container. Communication will not happen using containerName(hostName).To Check Go inside java web app container and ping maven web app container using name & IP. When we ping using ip it will work it will not be able to communicate using the name.Developers should not code the connectivity based on the IP in case of containers. Since the IP address of containers will be dynamic.IP will keep changing.

How To Create Coustm Bridge Network?

To create a Coustm Bridge Network

Syntax:

docker network create -d <driver> <networkName>

Example of Coustm Bridge Nwtwork

docker network create -d bridge Flipkart network

Inspect the Docker Networks by using the following command.

docker network inspect <networkNameOrId>

If containers are created in custom bridge network. Each container can access other using containerName/ContainerIP.Delete Containers which are running in default bridge or create container with different name.

The Default Bridge Network

Every installation of Docker provides a pre-built default Bridge Network with a Bridge driver scoped locally. You can verify the same using the network ls to know more commands refer to command.Docker – Instruction Commands.

sudo docker network ls

 default Bridge Network

Bridge Driver always provides single-host networking hence, the scope is local.

Connecting A Docker Container In Bridge Network

Note that the Bridge Network we saw in the previous step is the default network for Docker Containers. If you don’t specify any other network, all new Containers will be joined to this default network. To connect an Ubuntu Container to the default bridge network, use this command.

sudo docker run -dt ubuntu 

Connecting a Docker Container

Inspecting The Bridge Network

After you have created the Docker Container, check whether it is running or not.

sudo docker container ls

Inspecting the Bridge Network

Since the Container is already running, we can now use the network inspect command to inspect the Docker default bridge network.

sudo docker network inspect bridge



network inspect bridge

You can see the details related to the Bridge Network in JSON format. You can also check the Containers associated with the network in the Container object.

network inspect bridge

Testing The Network Connectivity

To test the network connectivity, note down the IP address of the Container. In this example, the IP address is “172.17.0.2/16”.We will ping this address from the Docker Host to check the connectivity.

ping 172.17.0.2



Testing the Network Connectivity

It shows that the host is able to ping the Docker Container in the network.

Differences Between User-Defined Bridges And The Default Bridge

Default Bridge Network

User Defined Bridges Network

The default bridge network will it will acts as an basic network isolation for the containers which are deployed in this network.

user defined network will allows you to create a coustm network with more configuration policies.

The containers which are deployed in default bridge network will able to communicate with each other by using the IP addresses.

The containers which are deployed in the coustm bridge network will able to communicate with each other by using the name of the containers.

Communication with the host system is done by using the host IP addresses.

Communication with the host system is done by using the host IP addresses.

Containers use the embedded DNS to commutation to the internet by the DNS resolution.

Containers use the embedded DNS to commutation to the internet by the DNS resolution.

Docker Bridge Network – FAQ’s

1. What Is The Difference Between Docker Network Bridge And Overlay?

Bridge network is an isolated with in the cluster the containers in different clusters can’t communicate with the container in the different cluster. If the containers are deployed in the overlay network they can communicate with the containers which are deployed in the different clusters.

2. What Is The Difference Between Bridged And Routed Connection?

A bridge and router see the two networks as a single entity, whereas a router sees the two networks as separate entities. This is the main distinction between the two.



Last Updated : 11 Sep, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads