skarlso
(Gergely Brautigam)
November 15, 2017, 10:33am
1
Hey there folks.
So I was trying to use this formatting example located in the docs:
docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
And it threw this into my face:
Template parsing error: template: :1:59: executing "" at <index $conf 0>: error calling index: index of untyped nil
I have no idea what the problem is. Could anyone please enlighten me?
Thank you!
kar1
(Kar1)
November 15, 2017, 12:08pm
2
Hi,
I think the issue is that the container on which you try the example has not port binding on the host.
If you do a simple inspect on the container, do you have a list of Ports with HostPort like this:
"NetworkSettings": {
...
"Ports": {
"50000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "50000"
}
],
"8080/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "80"
}
]
},
If you don’t have that but just something like that:
"NetworkSettings": {
...
"Ports": {
"8080/tcp": null
},
then you can’t iterate on a field (.HostPort) that does not exist.
skarlso
(Gergely Brautigam)
November 15, 2017, 12:13pm
3
Ahhhh! Thanks @kar1 ! That makes perfect sense.
Indeed the container did not have bindings.