Docker Series β€” Episode 14: Docker Networking Deep Dive (Bridge, Host, Overlay)

  • Thread starter Thread starter Yash Sonawane
  • Start date Start date
Y

Yash Sonawane

Guest
Welcome back to the Docker series! In the previous episode, we explored Docker Compose advanced scaling and multi-environment setups. Now, let’s dive into one of the most important and often overlooked aspects of Docker: Networking. Understanding how containers talk to each other and the outside world is critical for building real-world applications.

πŸ”Ή What You’ll Learn in This Episode​

  • Docker networking basics
  • Default Docker networks
  • Bridge, Host, and None networks
  • Overlay networks for multi-host communication
  • Connecting containers across networks
  • Real-world use cases

πŸ”Ή Docker Networking Basics​


Every container in Docker can communicate with others through networks. By default, Docker assigns containers to certain network drivers.

Run this to see networks:


Code:
docker network ls

Example output:


Code:
NETWORK ID     NAME      DRIVER    SCOPE
8d6f6a1c3f5e   bridge    bridge    local
c3d9d6b2af6e   host      host      local
9c7fda8e98bb   none      null      local

πŸ”Ή Bridge Network (Default)​

  • Default network type
  • Used when you run a container without specifying a network
  • Containers get an internal IP and can communicate using container names

Example:


Code:
docker run -dit --name container1 busybox sh

Code:
docker run -dit --name container2 busybox sh

Code:
docker network connect bridge container2

Now, container1 can ping container2 using its name.

πŸ”Ή Host Network​

  • Removes network isolation between container and host
  • Container shares the host’s networking stack
  • Best for high-performance networking

Example:


Code:
docker run -d --network host nginx

Now, Nginx runs directly on host’s IP.

⚠️ Downside: No container isolation.

πŸ”Ή None Network​

  • Completely disables networking
  • Useful for security-sensitive workloads

Code:
docker run -dit --network none busybox sh

This container has no internet access.

πŸ”Ή Overlay Network (Multi-Host Communication)​

  • Used in Docker Swarm or Kubernetes
  • Allows containers running on different hosts to communicate

Example (Swarm mode):


Code:
docker swarm init
docker network create -d overlay my_overlay

πŸ”Ή Connecting Containers Across Networks​


You can attach containers to multiple networks:


Code:
docker network create my_network

docker run -dit --name app1 --network my_network busybox sh

Containers on my_network can communicate securely.

πŸ”Ή Real-World Use Cases​

  • Bridge: Local development with multiple containers
  • Host: High-performance apps (e.g., monitoring agents)
  • None: Isolated environments
  • Overlay: Multi-host apps in production

πŸ”Ή Hands-On Challenge​

  1. Create a custom bridge network
  2. Run two containers and make them talk to each other using names
  3. Try host and none networks and compare behaviors

βœ… In this episode, you learned how Docker networking works β€” from bridge to overlay. Mastering this is crucial for scaling apps in production.

Continue reading...
 


Join 𝕋𝕄𝕋 on Telegram
Channel PREVIEW:
Back
Top