![Docker Networking](https://assets.community.aws/a/2c4SfCEBhoy9NYyu0Wdcw8DgF9Q/1-1-w.webp)
Docker Networking
Understanding Bridge, Host, and Overlay Networks | Enhancing Container Security with Custom Bridge Networks.
Published Feb 8, 2024
In Docker, networking is a crucial aspect that determines how containers communicate with each other and with external systems. Docker provides several networking options, including bridge, host, and overlay networks, each serving different purposes.
Let’s discuss these networking options and how to secure containers with a custom bridge network:
Bridge Network
Description: The bridge network is the default networking mode in Docker. It creates an internal network on the Docker host, allowing containers to communicate with each other and with external networks via NAT (Network Address Translation).
Use Cases: Bridge networks are suitable for standalone containers running on a single Docker host, providing isolation and allowing multiple containers to run on the same host without conflicting with each other.
Host Network:
Description: The host network mode removes network isolation between the container and the Docker host, allowing the container to use the host’s network stack directly. This means the container shares the host’s network namespace and can access network interfaces and ports directly without NAT.
Use Cases: Host network mode is suitable for scenarios where maximum network performance is required and network isolation is not a concern. It’s commonly used for high-performance applications or when the container needs to bind to specific network interfaces on the host.
Overlay Network:
Description: Overlay networks enable communication between containers across multiple Docker hosts or nodes in a Docker Swarm cluster. They use VXLAN (Virtual Extensible LAN) encapsulation to encapsulate and route traffic between containers running on different hosts.
Use Cases: Overlay networks are ideal for distributed applications deployed across multiple Docker hosts or nodes, providing seamless communication between containers regardless of their physical location.
![](https://assets.community.aws/a/2c4SaeORfi85S8pUET5MnRyaNeK/POC-JPG.webp)
First Run the docker login and log out of containers:
docker run -d — name login nginx: latest
docker run -d — name logout nginx: latest
![](https://assets.community.aws/a/2c4Smn9yAm6HZ4rMfnvKvYLY0rs/2-web.webp)
docker inspect 8365029c0fb5 and docker inspect 6dd651363699
![](https://assets.community.aws/a/2c4SreaCPqYsMPbcoLto5fpAWjC/3-web.webp)
![](https://assets.community.aws/a/2c4TGAxJB0ONxW0ZsJ5Mvv475o6/4-web.webp)
Install the ping command on the containers and check the ping status :
apt-get update and apt-get install iputils-ping
apt-get update and apt-get install iputils-ping
![](https://assets.community.aws/a/2c4TMWwWMEDAwPH09KNmxiR88Zp/5-web.webp)
check the docker networks available: docker network ls
![](https://assets.community.aws/a/2c4TS8qGWG80Q9fnOxiA4QMgvub/6-web.webp)
Create secure network command: docker network create secure-network.
![](https://assets.community.aws/a/2c4TbDJWk0oJiuBrDigDeohfzNt/7-web.webp)
Add payment container in new secure-network :
![](https://assets.community.aws/a/2c4Tg3YmBz7OExry4cWWuxiF25o/8-web.webp)
check the docker running containers :
![](https://assets.community.aws/a/2c4TlQWylDzM75P84jewG4XOO2d/9-web.webp)