Docker bridge networking¶
Docker bridge networking involves configuring a software bridge (often docker0 or a custom bridge like br1) to allow communication between containers and the host machine or across different hosts^[600-developer-docker-docker-bridge.md].
Configuration¶
To establish a bridge network, a virtual bridge device is created and configured with an IP address within the desired subnet^[600-developer-docker-docker-bridge.md]. Physical network interfaces (e.g., eth0) can be attached to this bridge to extend network connectivity^[600-developer-docker-docker-bridge.md].
For instance, to assign a static IP to the bridge and interface, the configuration files (e.g., /etc/sysconfig/network-scripts/ifcfg-br0) should define the DEVICE as the bridge and set the physical interface's BRIDGE parameter to point to it^[600-developer-docker-docker-bridge.md].
Docker daemon configuration¶
The Docker daemon can be configured to use a specific custom bridge instead of the default docker0^[600-developer-docker-docker-bridge.md]. This is typically done by modifying the Docker options (e.g., in /etc/sysconfig/docker) to include the -b flag to specify the bridge name^[600-developer-docker-docker-bridge.md].
When multiple hosts are connected via the same bridge, it is critical to prevent IP address conflicts^[600-developer-docker-docker-bridge.md]. This is managed by assigning non-overlapping IP ranges to each host using the --fixed-cidr parameter in the Docker configuration^[600-developer-docker-docker-bridge.md].
Common Commands¶
The brctl utility is commonly used to manage network bridges on the host system^[600-developer-docker-docker-bridge.md]. Key operations include:
- Create bridge:
brctl addbr <name> - Add interface:
brctl addif <bridge> <device> - Delete interface:
brctl delif <bridge> <device> - Delete bridge:
brctl delbr <name> - Show configuration:
brctl show^[600-developer-docker-docker-bridge.md]
Sources¶
600-developer-docker-docker-bridge.md
Related Concepts¶
- DevOps
- [[Virtualization]]