0

You can set up the test container to inspect with this,

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

When I run the following I get { 1234} however I want 1234 (no curly brackets, no spaces). How can I get this with podman/go?

$ podman inspect evanrox --format '{{index .NetworkSettings.Ports "1234/tcp" 0 }}'
{ 1234}

Again, I just want "1234"

1 Answer 1

0

The problem is you're getting an object with index .NetworkSettings.Ports "1234/tcp" 0 and in string context that's producing { 1234} which is a concatenation of the first value (an empty string) joined by a space and the second value which is 1234. The index is returning an object. But it's getting stringified. You would never know that without inspecting the return of index with json.

You can see with

$ podman inspect evanrox --format '{{ json ( index .NetworkSettings.Ports "1234/tcp" 0 ) }}'

That the result is

{"HostIp":"","HostPort":"1234"}

From there you can go

$ podman inspect evanrox --format '{{ json ( index .NetworkSettings.Ports "1234/tcp" 0 ).HostPort }}'

And then you'll see "1234" drop the json, and you get it

$ podman inspect evanrox --format '{{ ( index .NetworkSettings.Ports "1234/tcp" 0 ).HostPort }}'

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.