5

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" ?

1 Answer 1

6

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, a range may declare two variables, separated by a comma.

Not the answer you're looking for? Browse other questions tagged or ask your own question.