How to list container ip with docker inspect --format


#1

Hi,
I’m trying to find a way to list the exact ip of a container created with rancher 1.6. Normally in docker you would list that using docker inspect --format '{{ .NetworkSettings.IPAddress }}, which in Rancher context doesn’t exist, as Rancher uses different values, i.e. Labels: io.rancher.container.ip.

Of course, I tried using docker inspect --format '{{ .Labels.io.rancher.container.ip }}' , but it doesn’t work. Any ideas how I can go about this?


#2

You can try something like:

docker inspect $container_id --format '{{ index .Config.Labels "io.rancher.container.ip"}}'

#3

Thank you for the reply. Can you explain what index does in this context and why I couldn’t extract the values without it? How are they related to the upper functions such as Config or Labels?


#4

Index looks up the given key (2nd arg) in the given map (1st arg). This works when the key contains dots, while “.Labels.io.rancher.container.ip” is looking for the key “io” in “Labels”, then the key “rancher” in that, then “container”, then “ip”, and finds nothing.


#5

I understand, so it would have meant that there’s a hierarchy between ‘io’, ‘rancher’ and so on, when it obviously isnt’, it’s just the name of the variable. Right, thanks for the explanation.