Docker Networking and Bridge Configuration

4 Nov 2026, 11:2715 min readby ITYantra Admin

Complete guide to Docker networking including bridge, host, overlay, and macvlan networks, container communication, and port publishing.

# Docker Networking and Bridge Configuration

Introduction

Docker networking enables containers to communicate with each other and external systems. This tutorial covers Docker network drivers, bridge networking, container communication, port publishing, and network troubleshooting.

Learning Objectives

By the end of this tutorial, you will be able to:

  • Understand Docker network drivers (bridge, host, overlay, macvlan)
  • Create and manage custom networks
  • Enable container-to-container communication
  • Publish container ports to host
  • Troubleshoot Docker network issues

Technical Background

Docker Network Drivers

| Driver | Description | Use Case | |--------|-------------|----------| | bridge | Default for standalone containers | Single-host communication | | host | Container shares host network | Performance-critical apps | | overlay | Multi-host communication | Docker Swarm | | macvlan | Container gets MAC address | Legacy apps needing MAC | | none | No networking | Isolated containers |

Prerequisites

  • Docker installed and running

Hardware and Software Requirements

| Component | Requirement | |-----------|-------------| | Docker | v24+ |

Step-by-Step Implementation

Phase 1: Default Bridge Network

# List networks
docker network ls

# Inspect bridge network
docker network inspect bridge

# Run containers on default bridge
docker run -d --name web1 nginx:latest
docker run -d --name web2 nginx:latest

# Containers communicate by IP
docker exec web1 ping $(docker inspect -f '{{.NetworkSettings.IPAddress}}' web2)

Phase 2: Custom Bridge Network

# Create custom bridge network
docker network create --driver bridge myapp-network

# Run containers on custom network
docker run -d --name web --network myapp-network nginx:latest
docker run -d --name api --network myapp-network myapp:latest

# Containers communicate by name on custom network
docker exec web ping api

# Inspect network
docker network inspect myapp-network

Phase 3: Connect Container to Multiple Networks

# Create networks
docker network create frontend
docker network create backend

# Run container on frontend
docker run -d --name web --network frontend nginx:latest

# Connect to backend network
docker network connect backend web

# Disconnect from network
docker network disconnect backend web

Phase 4: Port Publishing

# Publish container port to host
docker run -d -p 8080:80 --name web nginx:latest

# Publish to specific host IP
docker run -d -p 127.0.0.1:8080:80 --name web nginx:latest

# Publish UDP port
docker run -d -p 53:53/udp --name dns mydns:latest

# Publish port range
docker run -d -p 7000-8000:7000-8000 --name myapp myapp:latest

# View published ports
docker port web 80

Phase 5: Host Network

# Container shares host network stack
docker run -d --net=host --name web nginx:latest

# Container port 80 is directly port 80 on host
# No port publishing needed

Phase 6: Overlay Network (Docker Swarm)

# Initialize swarm
docker swarm init --advertise-addr 192.168.1.10

# Create overlay network
docker network create -d overlay my-overlay

# Deploy service on overlay
docker service create --replicas 3 --network my-overlay --name web nginx:latest

Phase 7: Macvlan Network

# Create macvlan network
docker network create -d macvlan \
  --subnet=192.168.1.0/24 \
  --gateway=192.168.1.1 \
  -o parent=eth0 \
  macvlan_net

# Run container with own MAC and IP
docker run -d --network macvlan_net --name web nginx:latest

Phase 8: Container DNS

# Custom DNS
docker run -d --dns=8.8.8.8 --dns=8.8.4.4 --name web nginx:latest

# Check container DNS
docker exec web cat /etc/resolv.conf

# Custom network provides automatic DNS by container name
docker exec web getent hosts api

Expected Output

  • Custom Docker networks created
  • Containers communicate by name on custom networks
  • Ports published to host
  • Multi-network containers working

Verification Procedures

| Check | Command | Expected Result | |-------|---------|-----------------| | Networks | `docker network ls` | Custom networks listed | | Communication | `docker exec c1 ping c2` | Ping successful | | Port mapping | `docker ps` | Ports column populated | | DNS | `docker exec c1 getent hosts c2` | IP resolved |

Troubleshooting Scenarios

| Issue | Diagnosis | Resolution | |-------|-----------|------------| | Containers can't communicate | Different networks | Connect to same custom network | | Port not accessible | Not published | Add -p flag | | DNS fails | Using default bridge | Use custom bridge network | | Host can't reach container | Wrong network mode | Use host or publish ports |

Best Practices

  • **Use custom bridge networks:** Enable DNS service discovery
  • **Use container names:** Communicate by name, not IP
  • **Publish minimal ports:** Only expose necessary ports
  • **Isolate networks:** Separate frontend/backend with different networks
  • **Use overlay:** For multi-host Docker Swarm deployments

Security Considerations

  • **Network segmentation:** Isolate tiers with different networks
  • **Limit published ports:** Reduce attack surface
  • **Host network caution:** Removes container isolation
  • **Firewall:** Configure host firewall for container traffic

Conclusion

Docker networking provides flexible options for container communication. Understanding bridge, host, overlay, and macvlan drivers helps design networks meeting performance, security, and multi-host requirements.

References

  • Docker Networking: https://docs.docker.com/network/
  • Bridge Network: https://docs.docker.com/network/bridge/
  • Overlay Network: https://docs.docker.com/network/overlay/
  • Macvlan: https://docs.docker.com/network/macvlan/
#container-communication#macvlan#host#overlay#bridge#networking#Docker