mirror of
https://github.com/containers/podman.git
synced 2025-06-01 09:06:44 +08:00
fix create container: handle empty host port
Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
@ -223,7 +223,11 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup
|
|||||||
// publish
|
// publish
|
||||||
for port, pbs := range cc.HostConfig.PortBindings {
|
for port, pbs := range cc.HostConfig.PortBindings {
|
||||||
for _, pb := range pbs {
|
for _, pb := range pbs {
|
||||||
hostport, err := strconv.Atoi(pb.HostPort)
|
var hostport int
|
||||||
|
var err error
|
||||||
|
if pb.HostPort != "" {
|
||||||
|
hostport, err = strconv.Atoi(pb.HostPort)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,13 @@ class TestContainers(unittest.TestCase):
|
|||||||
containers = self.client.containers.list(all=True)
|
containers = self.client.containers.list(all=True)
|
||||||
self.assertEqual(len(containers), 2)
|
self.assertEqual(len(containers), 2)
|
||||||
|
|
||||||
|
def test_start_container_with_random_port_bind(self):
|
||||||
|
container = self.client.containers.create(image=constant.ALPINE,
|
||||||
|
name="containerWithRandomBind",
|
||||||
|
ports={'1234/tcp': None})
|
||||||
|
containers = self.client.containers.list(all=True)
|
||||||
|
self.assertTrue(container in containers)
|
||||||
|
|
||||||
def test_stop_container(self):
|
def test_stop_container(self):
|
||||||
top = self.client.containers.get(TestContainers.topContainerId)
|
top = self.client.containers.get(TestContainers.topContainerId)
|
||||||
self.assertEqual(top.status, "running")
|
self.assertEqual(top.status, "running")
|
||||||
|
Reference in New Issue
Block a user