Deep Dive into Docker 🐳Networking 🔌 and Its Types

Hey there! I am Deepak!! Passionate About Cloud & AWS☁️| DevOps ♾️ Technologies 👩🏻💻 And Skilled with Git 🔀 | Docker 🐳 | Kubernetes ☸ | Jenkins 🛠️
👏 Welcome to my blog!!
🚀 Introduction
Docker is a containerization platform that uses OS-level virtualization to package software applications and their dependencies into reusable units called containers. Docker containers can be run on any host with Docker or an equivalent container runtime installed, whether locally on your laptop or in a remote cloud.
Docker includes a networking system for managing communications between containers, your Docker host, and the outside world. Several different network types are supported, facilitating a variety of common use cases.
Docker networking is a fundamental aspect of containerization that allows containers to communicate with each other, the host, and external networks. In this blog, we'll explore the different types of Docker networking, their purposes, and use cases, and provide a practical example.
🏢 Impact in Real Life
📈 Scalability: Overlay networks enable seamless communication between backend services, even if distributed across different hosts.
🏞️ Isolation: Bridge networks ensure containers can communicate while being isolated from external networks.
⚡Performance: Host networking provides maximum throughput for the database container.
🧘Flexibility: Macvlan networks are ideal for scenarios where containers need unique MAC addresses.
🌐 Checking available networks in the system
Here we will check the available network layer in the system using the below command
ip address show
ip link show
ip link

Here you will see 2 by default network is showing in the system
Now after installing the docker, you can see that one more network layer is added which is docker0 so docker is used the docker0 network layer

✍️ Types of Docker Networking
Here are seven different types of Docker networks explained.
Bridge Network:
🌉 Description: Default network for containers on a single host.
🏠 Use Case: Applications with multiple containers needing communication within the same host.
📌 Key Points:
Isolated internal network.
Containers can access each other using container names as hostnames.
Containers can't directly access the host network.
Host Network:
🏠 Description: Containers share the host's network namespace.
🚀 Use Case: Performance-critical applications needing direct access to the host network.
📌 Key Points:
No network isolation between containers.
Containers use the host's network stack.
Optimal network performance.
Overlay Network:
🎭 Description: Spans multiple Docker daemons and hosts.
🌐 Use Case: Containers distributed across a cluster of machines requiring inter-host communication.
📌 Key Points:
Uses the overlay driver to create networks.
Facilitates seamless communication between containers on different hosts.
Suited for microservices architectures.
Macvlan Network:
🖥️ Description: Assigns a unique MAC address to each container.
🏢 Use Case: Containers needing direct connectivity to the physical network.
📌 Key Points:
Containers appear as separate physical devices on the network.
Provides a bridge between virtual and physical networks.
Enables containers to be part of VLANs.
None Network:
🚫 Description: Containers with no network access.
🔒 Use Case: Containers where network access is not needed, enhancing security.
📌 Key Points:
Containers are isolated from any network.
Suitable for containers with restricted functionality.
Custom Bridge Network:
🌉 Description: User-defined bridge network with custom configurations.
🛠️ Use Case: Fine-tuned networking requirements for specific applications.
📌 Key Points:
Users can create and manage their own bridge networks.
Provides more control over network settings.
Network Aliases:
🔗 Description: Assigning multiple network aliases to a container.
📊 Use Case: Running multiple services on a single container with different network identities.
📌 Key Points:
Containers can have multiple virtual network interfaces.
Useful for multi-service containers without launching separate containers.
📝 Managing Networks
Listing networks: You can list all your Docker networks with the command:
docker network ls
Creating a user-defined network: You can create the custom/user define network with the command:
docker network create <your-network-name>
You can see the new custom network is created as
my-networkDeleting the network: You can delete the network with the command:
docker network rm <your-network-name/id>
Delete all unused networks: You can automatically delete all unused networks using the
network prunecommand:docker network prune
🔗 Connecting Containers to Networks
You can create a new container without setting the --network flag then the containers will create within the default bridge network.

We can see the container added in the default bridge network.

You can attach new containers to a network by setting the --network flag with your docker run command.
Now create your own network add attach the network to the container

After inspecting the my-network you can see the newly created container con2 added into the custom network my-network

📡 Connecting Containers to Containers
Using Different Networking:
Here we will create two Ubuntu containers
con1in thedefault bridgenetwork andcon2in custommy-networkand let's see if can we able to achieve network isolation with the help of docker networking
Now try communicating between the two containers, using their names/id, Enter into the container
con1and try to connect to the containercon2
The containers aren’t in the same network yet, so they can’t directly communicate with each other.
Using the Same Networking:
Now, Here we will create two Ubuntu containers
con3andcon4in same custommy-network, and let's see how can we achieve network isolation with the help of docker networking.
Now try communicating between the two containers, using their names/id, Enter into the container
con3and try to connect to the containercon4
Now the containers are in the same network, so they can directly communicate with each other.
💻 Host Networking
Bridge networks are what you’ll most commonly use to connect your containers. Let’s also explore the capabilities of host networks, where containers attach directly to your host’s interfaces instead of docker0 network. You can enable host networking for a container by connecting it to the built-in host network
Here we will create nginx web server container in it and try to access it from the localhost

NGINX listens on port 80 by default. Because the container’s using a host network, you can access your NGINX server on your host’s localhost:80 or inEC2 instance IP Address even though no ports have been explicitly exposed
Note: If you are using EC2 instance make sure port 80 should be open in the inbound rule of the EC2 instance security group
Copy the IP address of the EC2 instance and paste it into the browser you are able to see the nginx page

🚫 None Networking
When a container’s networking is disabled, it will have no connectivity available – either to other containers or your wider network. Disable networking by attaching your container to the none network
Here we will create a container into none network and try to ping google.com

🤦♀️ Removing Containers from Networks
Docker lets you freely manage network connections without restarting your containers. In the previous section, you saw how to connect a container after its creation; it’s also possible to remove containers from networks they no longer need to participate in

Now the container is no belongs to my-network network

🎉🔑Conclusion:
🔗 Understanding Docker networking 🌐 and its types is crucial for designing efficient, scalable, and secure containerized applications. By leveraging the appropriate networking type for each scenario, you can optimize communication, performance, and isolation within your container ecosystem.
Special Thanks & Reference Video Shubham Londhe
Thank you🙏🙏... for taking the time to read this blog. I hope you found the information helpful and insightful. So please keep yourself updated with my latest insights and articles on DevOps 🚀 by following me on
So, Stay in the loop and stay ahead in the world of DevOps!
Happy Learning !... Keep Learning ! 😊



