Formatting docker network inspect output
I use to fight against the "--format" value of "docker network inspect" in order to get what I want.
One of the things often need is the "Subnet" and "Gateway", so I keep it here for the archives:
$ docker network inspect worpdress-network --format "{{(index .IPAM.Config 0).Gateway}}"
And also:
$ docker network inspect worpdress-network --format "{{(index .IPAM.Config 0).Subnet}} {{(index .IPAM.Config 0).Gateway}}"
But if I want to loop on the networks:
$ docker network list --format "{{.Name}}" bridge host neo4j-core-01-network neo4j-core-02-network neo4j-core-03-network none worpdress-network
That helps me to have my kind of "list of named network"
for N in $(sudo docker network list --format "{{.Name}}"); do sudo docker network inspect ${N} --format "{{(index .IPAM.Config 0).Subnet}} {{(index .IPAM.Config 0).Gateway}} {{.Name}}" 2>/dev/null ; done
Giving:
bridge 172.17.0.0/16 172.18.0.0/29 172.18.0.1 neo4j-core-01-network 172.18.0.8/29 172.18.0.9 neo4j-core-02-network 172.18.0.16/29 172.18.0.17 neo4j-core-03-network 172.19.0.0/16 172.19.0.1 worpdress-network
Note: blank lines are due to the "host" and "none" network, whch are dummy networks, without IP address assigned to them