Skip to content

Commit

Permalink
fix create container: handle empty host port
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Vasek <[email protected]>
  • Loading branch information
matejvasek authored and mheon committed Feb 18, 2021
1 parent 2f3ae7c commit 8dc2fb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/podman/common/create_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup
// publish
for port, pbs := range cc.HostConfig.PortBindings {
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 {
return nil, nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions test/python/docker/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ def test_start_container(self):
containers = self.client.containers.list(all=True)
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):
top = self.client.containers.get(TestContainers.topContainerId)
self.assertEqual(top.status, "running")
Expand Down

0 comments on commit 8dc2fb2

Please sign in to comment.