Merge pull request #29168 from Honny1/fix-json-format

Fix inspect template `.HostIp` for Docker compatibility
This commit is contained in:
Danish Prakash 2026-07-14 13:38:30 +05:30 committed by GitHub
commit 5561e6c416
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View file

@ -265,6 +265,12 @@ type InspectHostPort struct {
HostPort string `json:"HostPort"`
}
// HostIp allows Docker-compatible {{.HostIp}} access in Go templates.
// See https://github.com/containers/podman/issues/29164
func (hp InspectHostPort) HostIp() string {
return hp.HostIP
}
// InspectMount provides a record of a single mount in a container. It contains
// fields for both named and normal volumes. Only user-specified volumes will be
// included, and tmpfs volumes are not included even if the user specified them.

View file

@ -107,6 +107,19 @@ var _ = Describe("Podman container inspect", func() {
Expect(data[0].Config.Annotations[define.VolumesFromAnnotation]).To(Equal(volsctr))
})
// https://github.com/containers/podman/issues/29164
It("podman inspect supports docker-compatible HostIp in format template", func() {
ctrName := "hostip-compat"
session := podmanTest.Podman([]string{"create", "--name", ctrName, "-p", "127.0.0.1::8080/tcp", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
inspect := podmanTest.Podman([]string{"inspect", "--format", `{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostIp }}`, ctrName})
inspect.WaitWithDefaultTimeout()
Expect(inspect).Should(ExitCleanly())
Expect(inspect.OutputToString()).To(Equal("127.0.0.1"))
})
It("podman inspect hides secrets mounted to env", func() {
secretName := "mysecret"