7

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.

Jimmix
  • 5,644
  • 6
  • 44
  • 71

3 Answers3

10

Try these commands :

docker network inspect $(docker network ls | awk '$3 == "bridge" { print $1}') | jq -r '.[] | .Name + " " + .IPAM.Config[0].Subnet' -
Philippe
  • 20,025
  • 2
  • 23
  • 32
5
docker network inspect $(docker network ls -q)|grep -E "IPv(4|6)A"
Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
0

I use the following command in Bash

docker network ls --format "{{.Name}}" | while read i; do echo $i --- $(docker network inspect $i | grep Subnet); done

It reads network list and then gets Subnet field for each network.

Winand
  • 2,093
  • 3
  • 28
  • 48