Merge pull request #1 from redlahatarbus/cmd-and-hostname

feat: run container with hostname and command
This commit is contained in:
redlahatarbus
2024-08-16 11:04:51 -04:00
committed by GitHub
+27 -2
View File
@@ -26,17 +26,19 @@ class Container
private ?string $entryPoint = null;
/**
* @var array<string, string>
*/
* @var array<string, string>
*/
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 @@ class Container
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 @@ class Container
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 @@ class Container
$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 @@ class Container
$params[] = $this->image;
if (count($this->cmd) > 0) {
array_push($params, ...$this->cmd);
}
$this->process = new Process($params);
$this->process->mustRun();