Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libpod/define/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions test/system/500-networking.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,27 @@ EOF
fi
}

# Test for https://github.com/containers/podman/issues/29164
@test "podman inspect .NetworkSettings.Ports docker-compatible HostIp field" {
local cname="c-$(safename)"
local port=$(random_free_port)

run_podman run -d --name $cname -p "127.0.0.1:$port:8080/tcp" $IMAGE top
cid="$output"

# Docker-compatible template: .HostIp (json key casing, not Go field .HostIP)
run_podman inspect --format '{{ with (index (index .NetworkSettings.Ports "8080/tcp") 0) }}{{ printf "%s\t%s" .HostIp .HostPort }}{{ end }}' $cname
assert "$output" = "127.0.0.1 $port" \
"inspect .HostIp should work (docker compat)"

# Podman-native template: .HostIP (Go field name) should still work
run_podman inspect --format '{{ with (index (index .NetworkSettings.Ports "8080/tcp") 0) }}{{ printf "%s\t%s" .HostIP .HostPort }}{{ end }}' $cname
assert "$output" = "127.0.0.1 $port" \
"inspect .HostIP should also work (podman native)"

run_podman rm -f -t0 $cname
}

# Test for https://github.com/containers/podman/issues/18615
# CANNOT BE PARALLELIZED due to strict checking of /run/netns
@test "podman network cleanup --userns + --restart" {
Expand Down