From 9063ce801edba2e9a9e3d127d79d10dfa82b02b7 Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Thu, 10 Aug 2023 01:01:15 -0400 Subject: [PATCH] Allow networks to be created pre-emptively --- php/src/Docker/DockerActionManager.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index ef2a972bac6..93abcdcade0 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -780,6 +780,19 @@ private function ConnectContainerIdToNetwork(string $id, string $internalPort) : if ($e->getCode() !== 409) { throw $e; } + + // Network may have been created and connected preemptively + $url = $this->BuildApiUrl(sprintf('containers/%s/json', urlencode($id))); + try { + $response = $this->guzzleClient->get($url); + $responseBody = json_decode((string)$response->getBody(), true); + $connectedNetworks = $responseBody['NetworkSettings']['Networks']; + if (array_key_exists($network, $connectedNetworks)) { + return; + } + } catch (RequestException $e) { + // do nothing + } } $url = $this->BuildApiUrl(