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) {