From 7e8ebd346730952675fb76ada2e7f986458b047b Mon Sep 17 00:00:00 2001 From: nightio Date: Thu, 26 Feb 2026 18:02:42 +0100 Subject: [PATCH] Add support for container network aliases --- src/Container/GenericContainer.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Container/GenericContainer.php b/src/Container/GenericContainer.php index da3be02..ec63f99 100644 --- a/src/Container/GenericContainer.php +++ b/src/Container/GenericContainer.php @@ -64,6 +64,9 @@ class GenericContainer implements TestContainer protected ?string $networkName = null; + /** @var array */ + protected array $aliases = []; + protected ?string $user = null; protected ?string $workingDir = null; @@ -263,6 +266,16 @@ public function withNetwork(string $networkName): static return $this; } + /** + * @param array $aliases + */ + public function withAliases(array $aliases): static + { + $this->aliases = $aliases; + + return $this; + } + public function withPortGenerator(PortGenerator $portGenerator): static { $this->portGenerator = $portGenerator; @@ -412,10 +425,14 @@ protected function createContainerConfig(): ContainersCreatePostBody if ($this->networkName !== null) { $networkingConfig = new NetworkingConfig(); + $aliases = $this->aliases ?? []; + if ($this->name) { + $aliases[] = $this->name; + } $endpointsConfig = [ $this->networkName => new EndpointSettings([ 'networkID' => $this->networkName, - 'aliases' => $this->name ? [$this->name] : [], + 'aliases' => $aliases, ]), ]; $networkingConfig->setEndpointsConfig($endpointsConfig);