diff options
author | Milivoje Legenovic <m.legenovic@gmail.com> | 2021-03-02 01:16:31 +0100 |
---|---|---|
committer | Milivoje Legenovic <m.legenovic@gmail.com> | 2021-03-02 02:50:41 +0100 |
commit | 8b7caa6d04fc6a7c02bd0cbc05629508be546ac8 (patch) | |
tree | b56af6ba1b23b68e7f4d568115b6a58cf0d756b2 | |
parent | 8af66806c8042501ca32e66efdeb463cf5346cab (diff) | |
download | podman-8b7caa6d04fc6a7c02bd0cbc05629508be546ac8.tar.gz podman-8b7caa6d04fc6a7c02bd0cbc05629508be546ac8.tar.bz2 podman-8b7caa6d04fc6a7c02bd0cbc05629508be546ac8.zip |
Compat api containers/json Ports field is null
Fixes #9553
Signed-off-by: Milivoje Legenovic <m.legenovic@gmail.com>
-rw-r--r-- | pkg/api/handlers/compat/containers.go | 17 | ||||
-rw-r--r-- | test/apiv2/20-containers.at | 10 |
2 files changed, 26 insertions, 1 deletions
diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go index 971b6aa50..1e84888af 100644 --- a/pkg/api/handlers/compat/containers.go +++ b/pkg/api/handlers/compat/containers.go @@ -307,6 +307,21 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error } } + portMappings, err := l.PortMappings() + if err != nil { + return nil, err + } + + ports := make([]types.Port, len(portMappings)) + for idx, portMapping := range portMappings { + ports[idx] = types.Port{ + IP: portMapping.HostIP, + PrivatePort: uint16(portMapping.ContainerPort), + PublicPort: uint16(portMapping.HostPort), + Type: portMapping.Protocol, + } + } + return &handlers.Container{Container: types.Container{ ID: l.ID(), Names: []string{fmt.Sprintf("/%s", l.Name())}, @@ -314,7 +329,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error ImageID: imageID, Command: strings.Join(l.Command(), " "), Created: l.CreatedTime().Unix(), - Ports: nil, + Ports: ports, SizeRw: sizeRW, SizeRootFs: sizeRootFs, Labels: l.Labels(), diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at index 641c2adc3..4b40fde80 100644 --- a/test/apiv2/20-containers.at +++ b/test/apiv2/20-containers.at @@ -246,3 +246,13 @@ t GET containers/$cid/json 200 \ .Mounts[0].Destination="/test" t DELETE containers/$cid?v=true 204 + +# test port mapping +podman run -d --rm --name bar -p 8080:9090 $IMAGE top + +t GET containers/json 200 \ + .[0].Ports[0].PrivatePort=9090 \ + .[0].Ports[0].PublicPort=8080 \ + .[0].Ports[0].Type="tcp" + +podman stop bar |