0

When I run podman inspect I can get to a map[...] with --format. But indexing through it seems to be impossible.

$ podman run -d -p 1234:1234 --name evanrox alpine:3 sleep 360

$ podman inspect evanrox --format '{{ .NetworkSettings.Ports }}'
map[1234/tcp:[{ 1234}]]

However, these don't work,

--format '{{ .NetworkSettings.Ports.1234/tcp }}'
--format '{{ .NetworkSettings.Ports."1234/tcp" }}'
--format '{{ .NetworkSettings.Ports.[1234/tcp] }}'
--format '{{ .NetworkSettings.Ports.["1234/tcp"] }}'

I don't write Go. What's the right syntax?

1 Answer 1

0

index(obj, idx1, [idx2..])

You can index into a map with index,

index Returns the result of indexing its first argument by the following arguments. Thus index x 1 2 3 is, in Go syntax, x[1][2][3]. Each indexed item must be a map, slice, or array.

So in my case, I did

--format '{{ index .NetworkSettings.Ports "1234/tcp" }}'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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