Skip to content

Commit

Permalink
Merge pull request #5 from smurfy/network
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Mar 16, 2024
2 parents f6f40a5 + 585719f commit 4c9f39a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Container
private Process $process;
private WaitInterface $wait;

private ?string $network = null;
private ?string $healthCheckCommand = null;
private int $healthCheckIntervalInMS;

Expand Down Expand Up @@ -85,6 +86,13 @@ public function withMount(string $localPath, string $containerPath): self
return $this;
}

public function withNetwork(string $network): self
{
$this->network = $network;

return $this;
}

public function run(bool $wait = true): self
{
$this->id = uniqid('testcontainer', true);
Expand All @@ -111,6 +119,11 @@ public function run(bool $wait = true): self
$params[] = $this->healthCheckIntervalInMS . 'ms';
}

if ($this->network !== null) {
$params[] = '--network';
$params[] = $this->network;
}

$params[] = $this->image;

$this->process = new Process($params);
Expand Down Expand Up @@ -210,6 +223,10 @@ public function logs(): string

public function getAddress(): string
{
if ($this->network !== null && !empty($this->inspectedData[0]['NetworkSettings']['Networks'][$this->network]['IPAddress'])) {
return $this->inspectedData[0]['NetworkSettings']['Networks'][$this->network]['IPAddress'];
}

return $this->inspectedData[0]['NetworkSettings']['IPAddress'];
}
}

0 comments on commit 4c9f39a

Please sign in to comment.