Name your docker bridges with Ansible
I recently wanted to debug something on my linux server and listed all bridges. The output was disappointing. All bridges were named with random strings like this:
br-2b6b3cc75104 |
I create all my bridges with ansible and it seems that the ansible docker_network module is not very good at naming things in a human readable way. But there is a way you can influence the system bridge names when using docker through ansible.
The following applies to Linux systems.
Where do ansible managed docker bridge names come from?
When you create a new docker network with ansible, docker creates a new system bridge for you. The name consists of a prefix br-
and a hex string with the first 12 characters of the id of the docker network that uses the bridge.
How to name ansible managed docker bridges
To assign a name to the system bridge when creating a docker network with ansible you can pass the driver option com.docker.network.bridge.name
. The bridge name has a 15 character limit. Consider the following example of an ansible task that creates a network and sets the bridge name:
- name: Ensure plausible network |
How to find out which bridge belongs to which docker network
When you already have several bridges with random names and you need to find out which docker network they belong to, you can inspect the docker network and look for the network id. The bridge name will use the first 12 characters of the docker network id as an identifier:
benjamin@tnglab:~$ docker network inspect wekan |
In this example the bridge name would be br-56055d95f648
.
How does it look in practice?
Setting the bridge names, I went from this:
benjamin@tnglab:~$ brctl show |
To this:
benjamin@tnglab:~$ brctl show |
Much more helpful. And I even forgot what I wanted to debug in the first place. Problem solved…