Skip to content

Commit

Permalink
Merge pull request #7 from echozio/feat/published-ports
Browse files Browse the repository at this point in the history
feat: allow publishing ports for containers
  • Loading branch information
shyim committed May 16, 2024
2 parents 4c9f39a + 7db5275 commit a24f1d5
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 a24f1d5

Please sign in to comment.