I am trying to get the network name of containers. I tried:
docker inspect db_dev -f "{{index .NetworkSettings.Networks }}"
returns:
map[mynet_default:0xc0005dc000]
How do I return the string "mynet_default" ?
Base on this answer:
docker inspect db_dev \
-f '{{range $k, $v := .NetworkSettings.Networks}}{{print $k}}{{end}}'
You might want to use printf "%s\n" $k
if there are multiple networks otherwise they will be concatenated without separator.
From the range
documentation:
If a
range
action initializes a variable, the variable is set to the successive elements of the iteration. Also, arange
may declare two variables, separated by a comma.