i am creating a docker network using "docker network create --d bridge mynet". I want to get the bridge name that is associated to this docker network.
I know i can use the "-o" to provide bridge name. ex :"docker network create --d bridge -o com.docker.network.bridge.name=mybridge mynet". This method will work with normal bridge driver but in my case, I am using an ovs driver hence i am starting the network as "docker network create --d ovs mynet". If i use the "-o" in case of ovs driver it does not work.
please suggest me a way to get the bridge name associated to a network. The new bridge which is being created when i create the network,the bridge which has been created with it has a random name and i can see it using "ifconfig" command.
Bridge name is not part of docker network inspect
output, but it's always br-<first 12 characters of network id>
(unless explicitly specified when creating the network with -o com.docker.network.bridge.name=<bridge name>
).
network_id=$(docker network inspect -f {{.Id}} <network name>)
bridge_name="br-${network_id:0:12}"
Another option is to rely on the fact that the bridge serves as network's default gateway and therefore its IP address and network's gateway address are the same.
network_gateway=$(docker inspect \
-f '{{range .IPAM.Config}}{{.Gateway}}{{end}}' <network name>)
bridge_name=$(ifconfig | grep -B1 "inet $network_gateway" | head -1 | cut -d: -f1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With