From cb980f9e846183e65de5245a4a2994fefcdf432b Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 2 Jan 2023 17:37:57 +0100 Subject: [PATCH] fix exposing containers Signed-off-by: Simon L --- php/src/Container/ContainerPort.php | 4 ++-- php/src/ContainerDefinitionFetcher.php | 11 +++++++++++ php/src/Docker/DockerActionManager.php | 20 ++++---------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/php/src/Container/ContainerPort.php b/php/src/Container/ContainerPort.php index 577a0bd4..3ecf56cd 100644 --- a/php/src/Container/ContainerPort.php +++ b/php/src/Container/ContainerPort.php @@ -5,12 +5,12 @@ namespace AIO\Container; class ContainerPort { public string $port; public string $ipBinding; - public bool $protocol; + public string $protocol; public function __construct( string $port, string $ipBinding, - bool $protocol + string $protocol ) { $this->port = $port; $this->ipBinding = $ipBinding; diff --git a/php/src/ContainerDefinitionFetcher.php b/php/src/ContainerDefinitionFetcher.php index dc0b3e11..1766fc6c 100644 --- a/php/src/ContainerDefinitionFetcher.php +++ b/php/src/ContainerDefinitionFetcher.php @@ -77,6 +77,17 @@ class ContainerDefinitionFetcher $ports = new ContainerPorts(); foreach ($entry['ports'] as $value) { + + if ($value['port_number'] === '%APACHE_PORT%') { + $value['port_number'] = $this->configurationManager->GetApachePort(); + } elseif ($value['port_number'] === '%TALK_PORT%') { + $value['port_number'] = $this->configurationManager->GetTalkPort(); + } + + if ($value['ip_binding'] === '%APACHE_IP_BINDING%') { + $value['ip_binding'] = $this->configurationManager->GetApacheIPBinding(); + } + $ports->AddPort( new ContainerPort( $value['port_number'], diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index 5742f58b..141cf064 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -361,31 +361,19 @@ class DockerActionManager $exposedPorts = []; if ($container->GetInternalPort() !== 'host') { foreach($container->GetPorts()->GetPorts() as $value) { - $exposedPorts[$value->port] = null; + $portWithProtocol = $value->port . '/' . $value->protocol; + $exposedPorts[$portWithProtocol] = null; } } if(count($exposedPorts) > 0) { + $requestBody['ExposedPorts'] = $exposedPorts; foreach ($container->GetPorts()->GetPorts() as $value) { $port = $value->port; - if($port === '%APACHE_PORT%') { - $port = $this->configurationManager->GetApachePort(); - } elseif($port === '%TALK_PORT%') { - $port = $this->configurationManager->GetTalkPort(); - } - $ipBinding = $value->ipBinding; - if($ipBinding === '%APACHE_IP_BINDING%') { - $ipBinding = $this->configurationManager->GetApacheIPBinding(); - } - if ($ipBinding === '') { - $ipBinding = '0.0.0.0'; - } - $protocol = $value->protocol; $portWithProtocol = $port . '/' . $protocol; - $requestBody['ExposedPorts'][$portWithProtocol] = null; - $requestBody['HostConfig']['PortBindings'][$port] = [ + $requestBody['HostConfig']['PortBindings'][$portWithProtocol] = [ [ 'HostPort' => $port, 'HostIp' => $ipBinding,