Skip to content

Commit 7e8ebd3

Browse files
committed
Add support for container network aliases
1 parent 4c43b63 commit 7e8ebd3

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/Container/GenericContainer.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class GenericContainer implements TestContainer
6464

6565
protected ?string $networkName = null;
6666

67+
/** @var array<string> */
68+
protected array $aliases = [];
69+
6770
protected ?string $user = null;
6871

6972
protected ?string $workingDir = null;
@@ -263,6 +266,16 @@ public function withNetwork(string $networkName): static
263266
return $this;
264267
}
265268

269+
/**
270+
* @param array<string> $aliases
271+
*/
272+
public function withAliases(array $aliases): static
273+
{
274+
$this->aliases = $aliases;
275+
276+
return $this;
277+
}
278+
266279
public function withPortGenerator(PortGenerator $portGenerator): static
267280
{
268281
$this->portGenerator = $portGenerator;
@@ -412,10 +425,14 @@ protected function createContainerConfig(): ContainersCreatePostBody
412425

413426
if ($this->networkName !== null) {
414427
$networkingConfig = new NetworkingConfig();
428+
$aliases = $this->aliases ?? [];
429+
if ($this->name) {
430+
$aliases[] = $this->name;
431+
}
415432
$endpointsConfig = [
416433
$this->networkName => new EndpointSettings([
417434
'networkID' => $this->networkName,
418-
'aliases' => $this->name ? [$this->name] : [],
435+
'aliases' => $aliases,
419436
]),
420437
];
421438
$networkingConfig->setEndpointsConfig($endpointsConfig);

0 commit comments

Comments
 (0)