mirror of
https://github.com/containers/podman.git
synced 2025-05-20 16:47:39 +08:00
update podman socket output to include also exposed ports
Fixes https://github.com/containers/podman/issues/25851 Co-authored-by: Brent Baude <bbaude@redhat.com> Signed-off-by: Cesar Goncalves <mail@cesargoncalves.com>
This commit is contained in:
@ -342,25 +342,46 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
portMappings, err := l.PortMappings()
|
inspect, err := l.Inspect(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ports := make([]container.Port, len(portMappings))
|
ports := []container.Port{}
|
||||||
for idx, portMapping := range portMappings {
|
for portKey, bindings := range inspect.NetworkSettings.Ports {
|
||||||
ports[idx] = container.Port{
|
portNum, proto, ok := strings.Cut(portKey, "/")
|
||||||
IP: portMapping.HostIP,
|
if !ok {
|
||||||
PrivatePort: portMapping.ContainerPort,
|
return nil, fmt.Errorf("PORT/PROTOCOL format required for %q", portKey)
|
||||||
PublicPort: portMapping.HostPort,
|
|
||||||
Type: portMapping.Protocol,
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
inspect, err := l.Inspect(false)
|
containerPort, err := strconv.Atoi(portNum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(bindings) == 0 {
|
||||||
|
// Exposed but not published
|
||||||
|
ports = append(ports, container.Port{
|
||||||
|
PrivatePort: uint16(containerPort),
|
||||||
|
Type: proto,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
for _, b := range bindings {
|
||||||
|
hostPortInt, err := strconv.Atoi(b.HostPort)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid HostPort: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ports = append(ports, container.Port{
|
||||||
|
IP: b.HostIP,
|
||||||
|
PrivatePort: uint16(containerPort),
|
||||||
|
PublicPort: uint16(hostPortInt),
|
||||||
|
Type: proto,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
n, err := json.Marshal(inspect.NetworkSettings)
|
n, err := json.Marshal(inspect.NetworkSettings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -427,7 +427,17 @@ t GET containers/json 200 \
|
|||||||
.[0].Ports[0].PublicPort=8080 \
|
.[0].Ports[0].PublicPort=8080 \
|
||||||
.[0].Ports[0].Type="tcp"
|
.[0].Ports[0].Type="tcp"
|
||||||
|
|
||||||
podman stop bar
|
podman rm -f bar
|
||||||
|
|
||||||
|
# confirm exposed port 8080 shows up in /containers/json
|
||||||
|
|
||||||
|
podman run -d --rm --name bar --expose 8080 $IMAGE top
|
||||||
|
|
||||||
|
t GET containers/json 200 \
|
||||||
|
.[0].Ports[0].PrivatePort=8080 \
|
||||||
|
.[0].Ports[0].Type="tcp"
|
||||||
|
|
||||||
|
podman rm -f bar
|
||||||
|
|
||||||
#compat api list containers sanity checks
|
#compat api list containers sanity checks
|
||||||
podman run -d --rm --name labelcontainer_with --label slartibart=fast $IMAGE top
|
podman run -d --rm --name labelcontainer_with --label slartibart=fast $IMAGE top
|
||||||
|
Reference in New Issue
Block a user