Sitemap

Docker Networking

3 min readMar 27, 2024

--

Connecting Containers Seamlessly

Press enter or click to view image in full size
Image Source: Freepik

we’ll explore Docker networking fundamentals, delve into different networking types, and shed light on the workings of custom bridge networks.

Docker Networking Architecture

At its core, Docker networking enables communication between containers and the host system. Every container has its own eth0 interface with a unique IP address, while the host system also possesses its eth0 interface. Docker introduces a virtual Ethernet interface, known as Docker0 or bridge network, which bridges the container’s eth0 with the host’s eth0. This bridge network serves as the backbone for container networking, enabling seamless communication.

Press enter or click to view image in full size
Networking Architecture

Types of Docker Networking

  1. Bridge Networking: By default, Docker containers are connected to the bridge network, allowing them to communicate with each other. This approach provides a level of isolation while enabling container-to-container communication within the same host.
  2. Host Networking: In host networking mode, containers share the network namespace with the host, utilizing its IP address directly. While this mode offers maximum performance, it compromises container isolation, making it less secure.
  3. Overlay Networking: Designed for distributed applications spanning multiple hosts, overlay networking establishes a network that spans across multiple Docker hosts. Although more complex to set up, overlay networks facilitate seamless communication between containers regardless of their physical location.

Custom Bridge Networking:

Custom bridge networking allows users to establish their own segregated networks designed to meet particular needs. The following command generates a custom bridge network:

docker network create <network_name>

Users can define custom bridge networks with unique configurations. These networks offer enhanced isolation, allowing containers to communicate within the same network while remaining isolated from containers in other networks.

Working
Custom bridge networks facilitate the isolation of containers by segregating them into distinct networks. Containers within the same custom bridge network can communicate with each other, while those in different networks remain isolated. This isolation ensures enhanced security and enables fine-grained control over network traffic between containers.

Press enter or click to view image in full size
Custome Bridge Network

Commands:

  1. Commands for custom bridge network

docker network create <network_name>

Get Arjun Pawar’s stories in your inbox

Join Medium for free to get updates from this writer.

docker run -d --name <conatiner_name> --network=<network_name> <image_name>

2. Commands for host network

docker run -d --name <container_name> --network=host <image_name>

3. To inspect network type of conatiner

docker inspect <container_name> and then check for NetworkSettings

4. To ping another container

docker exec -it <container_name> /bin/bash : login into application

apt-get install iputils-ping -y : Install ping

ping <IP_address_another_container> : Ping another application

Code Snippets:

Press enter or click to view image in full size
Custom Bridge Network
Press enter or click to view image in full size
Host Network

Conclusion:

Docker networking plays a pivotal role in orchestrating containerized environments, enabling seamless communication and robust isolation.

Hey there! 👋 If you’ve found this blog insightful and helpful, why not spread the knowledge to your peers?

Additional Resources:

Explore these resources to deepen your understanding of Docker Networking!!!

--

--