Docker allows you to create dedicated channels between multiple Docker Containers to create a network of Containers that can share files and other resources with each other. 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.
Step 1: The default Bridge Network
Every installation of Docker provides a pre-built default Bridge Network with Bridge driver scoped locally. You can verify the same using the network ls command.
sudo docker network ls
Bridge Driver always provides single-host networking hence, the scope is local.
Step 2: Connecting a Docker Container
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
Step 3: Inspecting the Bridge Network
After you have created the Docker Container, check whether it is running or not.
sudo docker container ls
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
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.
Step 4: 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.
It shows that the host is able to ping the Docker Container in the network.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.