Skip to content

Commit

Permalink
feat: allow publishing ports for containers
Browse files Browse the repository at this point in the history
  • Loading branch information
echozio committed May 15, 2024
1 parent 4c9f39a commit 7db5275
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class Container
*/
private array $mounts = [];

/**
* @var array<string>
*/
private array $ports = [];

protected function __construct(private string $image)
{
$this->wait = new WaitForNothing();
Expand Down Expand Up @@ -86,6 +91,14 @@ public function withMount(string $localPath, string $containerPath): self
return $this;
}

public function withPort(string $localPort, string $containerPort): self
{
$this->ports[] = '-p';
$this->ports[] = sprintf('%s:%s', $localPort, $containerPort);

return $this;
}

public function withNetwork(string $network): self
{
$this->network = $network;
Expand All @@ -105,6 +118,7 @@ public function run(bool $wait = true): self
'--name',
$this->id,
...$this->mounts,
...$this->ports,
];

foreach ($this->env as $name => $value) {
Expand Down

0 comments on commit 7db5275

Please sign in to comment.