Search code examples
bashdockeripcommand-line-interfacesubnet

Docker get a list of created networks' IP addresses (IP range of subnets)


If you use command:

docker network ls

you'll get the output that lists all Docker networks but lacking the IP range of these networks.

how to get all created sub networks IP ranges?

for example if I use command:

docker network create --subnet 172.31.0.1/16 --internal network-one
docker network create --subnet 173.31.0.1/16 --internal network-two

I would like to get list of the address ranges containing

172.31.0.1/16
173.31.0.1/16

Perfectly if I could get the list as CLI output in a format:

network-one 172.31.0.1/16
network-two 173.31.0.1/16
...

so I could load it as Bash array and parse it later line by line or pipe to another CLI command.


Solution

  • Try these commands :

    docker network inspect $(docker network ls | awk '$3 == "bridge" { print $1}') | jq -r '.[] | .Name + " " + .IPAM.Config[0].Subnet' -