From 7db52752963f311809924241c8c6c29ded6792aa Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 15 May 2024 14:49:42 +0200 Subject: [PATCH] feat: allow publishing ports for containers --- src/Container/Container.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Container/Container.php b/src/Container/Container.php index 3ba7e0c..9e92bf7 100644 --- a/src/Container/Container.php +++ b/src/Container/Container.php @@ -39,6 +39,11 @@ class Container */ private array $mounts = []; + /** + * @var array + */ + private array $ports = []; + protected function __construct(private string $image) { $this->wait = new WaitForNothing(); @@ -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; @@ -105,6 +118,7 @@ public function run(bool $wait = true): self '--name', $this->id, ...$this->mounts, + ...$this->ports, ]; foreach ($this->env as $name => $value) {