fix adding containers to the host network

Signed-off-by: Simon L <szaimen@e.mail.de>
This commit is contained in:
Simon L 2023-01-02 16:42:08 +01:00
parent eaabc8e4b0
commit 5f63e90922

View file

@ -363,6 +363,8 @@ class DockerActionManager
foreach($container->GetPorts()->GetPorts() as $value) { foreach($container->GetPorts()->GetPorts() as $value) {
$exposedPorts[$value->port] = null; $exposedPorts[$value->port] = null;
} }
} else {
$requestBody['HostConfig']['NetworkMode'] = 'host';
} }
if(count($exposedPorts) > 0) { if(count($exposedPorts) > 0) {
@ -633,31 +635,31 @@ class DockerActionManager
private function ConnectContainerIdToNetwork(string $id, string $internalPort) : void private function ConnectContainerIdToNetwork(string $id, string $internalPort) : void
{ {
if ($internalPort === 'host') { if ($internalPort === 'host') {
$network = 'host'; return;
} else { }
$network = 'nextcloud-aio';
$url = $this->BuildApiUrl('networks/create'); $network = 'nextcloud-aio';
try { $url = $this->BuildApiUrl('networks/create');
$this->guzzleClient->request( try {
'POST', $this->guzzleClient->request(
$url, 'POST',
[ $url,
'json' => [ [
'Name' => 'nextcloud-aio', 'json' => [
'CheckDuplicate' => true, 'Name' => 'nextcloud-aio',
'Driver' => 'bridge', 'CheckDuplicate' => true,
'Internal' => false, 'Driver' => 'bridge',
'Options' => [ 'Internal' => false,
'com.docker.network.bridge.enable_icc' => 'true' 'Options' => [
] 'com.docker.network.bridge.enable_icc' => 'true'
] ]
] ]
); ]
} catch (RequestException $e) { );
// 409 is undocumented and gets thrown if the network already exists. } catch (RequestException $e) {
if ($e->getCode() !== 409) { // 409 is undocumented and gets thrown if the network already exists.
throw $e; if ($e->getCode() !== 409) {
} throw $e;
} }
} }