Master Docker Networking: From Bridge to Overlay and Macvlan Explained
This comprehensive guide explains Docker's networking fundamentals, covering network types such as bridge, host, overlay, and macvlan, their drivers, configurations, security considerations, and practical command‑line examples for creating, managing, and troubleshooting container networks in both single‑host and multi‑host environments.
Docker networking is a core component of Docker container technology, responsible for managing communication between containers and the external world.
1. Overview
Each Docker container is treated as an independent network entity with its own IP address, network interface, and routing rules. Docker provides several network options—bridge, host, overlay, macvlan, and none—to suit different deployment scenarios.
1.1 Docker Network Types
Bridge Network : The default network type; containers connect to an internal private bridge.
Host Network : Containers share the host’s network namespace and use the host’s network interfaces directly.
Overlay Network : Used in Docker Swarm clusters to enable communication between containers on different Docker daemons.
Macvlan Network : Gives containers their own MAC address, allowing direct mapping to the physical network.
None Network : Containers have a network namespace but no network interfaces are configured.
1.2 Network Drivers
Docker network drivers implement the different network types. Built‑in drivers include bridge, overlay, host and macvlan. Third‑party drivers can also be installed.
1.3 Container Network Modes
Bridge Mode : Default mode; each container has an isolated network namespace.
Host Mode : Containers share the host’s network stack, eliminating network isolation.
None Mode : Containers have their own stack but no interfaces are configured.
Overlay Mode : Used in Docker Swarm to enable cross‑host container communication.
1.4 Network Configuration and Management
Docker networks are managed via the CLI. Common commands include docker network create, docker network ls, docker network connect and docker network disconnect.
1.5 Security and Isolation
Docker networks isolate containers by default; containers on different networks cannot communicate unless explicit rules are set.
2. Bridge Network (bridge)
2.1 Basic Concept
The bridge network is Docker’s default mode. The Docker host creates a virtual bridge that allows containers to communicate with each other and the external network while keeping them isolated from the host.
2.2 How It Works
When a container starts without a specified network, it connects to the host’s default bridge. Docker assigns an IP address and a virtual interface, then attaches the interface to the bridge. NAT is used to reach the physical network.
2.3 Creating and Managing
1. Create a custom bridge network
Use the following command:
docker network create --driver bridge my_bridge_network2. Connect a container to the bridge network
Specify the network at container start:
docker run -d --name my_container --network my_bridge_network my_image3. View network information
Inspect the network details:
docker network inspect my_bridge_network2.4 Network Isolation and Communication
Only containers attached to the same bridge network can communicate, providing a basis for secure multi‑container applications.
2.5 Port Mapping
Port mapping exposes container ports on the host, e.g.: docker run -d -p 8080:80 my_web_server_image The bridge network is the most commonly used Docker network mode.
3. Host Network (host)
The host network mode offers high performance but reduces isolation, so it should be used with caution.
3.1 Basic Concept
Containers share the host’s network namespace, using the host’s interfaces directly, which eliminates the overhead of Docker’s virtual networking.
3.2 How It Works
Containers have no separate IP address; they bind directly to the host’s IP and ports.
3.3 Use Cases
Performance‑sensitive applications : Maximize network throughput.
Port conflicts : Use host ports directly to avoid mapping issues.
Network monitoring : Full visibility into network traffic.
3.4 How to Use
Run a container with the --network host option:
docker run -d --network host --name my_host_network_container my_image4. Overlay Network
Overlay networks enable cross‑host container communication in Docker Swarm clusters, ideal for large‑scale deployments despite some performance overhead.
4.1 Basic Concept
Overlay networks are a high‑level Docker network type for Swarm, allowing containers on different hosts to communicate as if they were on the same network.
4.2 How It Works
They use drivers such as VXLAN to encapsulate traffic between hosts, creating a virtual network layer over the physical infrastructure.
4.3 Use Cases
Multi‑host container deployment
Docker Swarm clusters
Cross‑host load balancing
4.4 How to Use
Create an overlay network in a Swarm:
docker network create -d overlay my_overlay_networkDeploy a service on the overlay network:
docker service create --name my_service --network my_overlay_network my_image4.5 Considerations
Network performance : Encapsulation adds overhead.
Security : Encryption options are available.
Management : Requires understanding of Swarm networking.
5. Macvlan Network
Macvlan networks give containers direct access to the physical network, making them appear as independent devices, which is useful for high‑performance or legacy integration scenarios but introduces complexity and security challenges.
5.1 Basic Concept
Each container receives its own MAC address and can be assigned an IP address on the physical network, bypassing Docker’s virtual networking.
5.2 How It Works
Macvlan creates virtual interfaces attached to the host’s physical NIC; containers communicate through these interfaces directly.
5.3 Use Cases
Direct network access : Bypass NAT.
Legacy system integration
Performance‑critical workloads
5.4 How to Use
Create a macvlan network:
docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=eth0 my_macvlan_netRun a container on the macvlan network:
docker run --network my_macvlan_net --name my_container my_image5.5 Considerations
Isolation : Containers are exposed on the physical network.
Routing and firewall : Additional configuration may be required.
Host communication : Containers may not communicate with the host without extra setup.
6. Conclusion
Docker networking is essential for containerized applications, offering various network types and configurations to meet a wide range of scenarios—from simple single‑host deployments to complex multi‑host Swarm clusters. Choosing the appropriate network type and configuring it properly enables developers and operators to build efficient, secure, and manageable container environments.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
