From 6d85ffe6daa15c017bbaa74bbe68c34fa3c86122 Mon Sep 17 00:00:00 2001 From: redlahatarbus <46457154+redlahatarbus@users.noreply.github.com> Date: Fri, 16 Aug 2024 10:04:54 -0400 Subject: [PATCH 1/2] feat: run container with hostname and command --- src/Container/Container.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Container/Container.php b/src/Container/Container.php index 0ea8ebf..aabe8c3 100644 --- a/src/Container/Container.php +++ b/src/Container/Container.php @@ -26,17 +26,19 @@ class Container private ?string $entryPoint = null; /** - * @var array - */ + * @var array + */ private array $env = []; private Process $process; private WaitInterface $wait; + private ?string $hostname = null; private bool $privileged = false; private ?string $network = null; private ?string $healthCheckCommand = null; private int $healthCheckIntervalInMS; + private array $cmd = []; /** * @var ContainerInspect @@ -68,6 +70,13 @@ public function getId(): string return $this->id; } + public function withHostname(string $hostname): self + { + $this->hostname = $hostname; + + return $this; + } + public function withEntryPoint(string $entryPoint): self { $this->entryPoint = $entryPoint; @@ -104,6 +113,13 @@ public function withHealthCheckCommand(string $command, int $healthCheckInterval return $this; } + public function withCmd(array $cmd): self + { + $this->cmd = $cmd; + + return $this; + } + public function withMount(string $localPath, string $containerPath): self { $this->mounts[] = '-v'; @@ -166,6 +182,11 @@ public function run(bool $wait = true): self $params[] = $this->network; } + if ($this->hostname !== null) { + $params[] = '--hostname'; + $params[] = $this->hostname; + } + if ($this->entryPoint !== null) { $params[] = '--entrypoint'; $params[] = $this->entryPoint; @@ -177,6 +198,10 @@ public function run(bool $wait = true): self $params[] = $this->image; + if (count($this->cmd) > 0) { + array_push($params, ...$this->cmd); + } + $this->process = new Process($params); $this->process->mustRun(); From b9c1424d14c62e2b52812cfdd6e990d06b9662c2 Mon Sep 17 00:00:00 2001 From: redlahatarbus <46457154+redlahatarbus@users.noreply.github.com> Date: Sat, 17 Aug 2024 11:12:30 -0400 Subject: [PATCH 2/2] fix: type cmd to array string --- src/Container/Container.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Container/Container.php b/src/Container/Container.php index aabe8c3..7b569b9 100644 --- a/src/Container/Container.php +++ b/src/Container/Container.php @@ -38,6 +38,10 @@ class Container private ?string $network = null; private ?string $healthCheckCommand = null; private int $healthCheckIntervalInMS; + + /** + * @var array + */ private array $cmd = []; /**