mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-12 08:29:34 +00:00
Merge pull request #16 from redlahatarbus/main
Adding ability to run docker container with hostname and command
This commit is contained in:
@@ -26,18 +26,24 @@ class Container
|
|||||||
private ?string $entryPoint = null;
|
private ?string $entryPoint = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array<string, string>
|
* @var array<string, string>
|
||||||
*/
|
*/
|
||||||
private array $env = [];
|
private array $env = [];
|
||||||
|
|
||||||
private Process $process;
|
private Process $process;
|
||||||
private WaitInterface $wait;
|
private WaitInterface $wait;
|
||||||
|
|
||||||
|
private ?string $hostname = null;
|
||||||
private bool $privileged = false;
|
private bool $privileged = false;
|
||||||
private ?string $network = null;
|
private ?string $network = null;
|
||||||
private ?string $healthCheckCommand = null;
|
private ?string $healthCheckCommand = null;
|
||||||
private int $healthCheckIntervalInMS;
|
private int $healthCheckIntervalInMS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string>
|
||||||
|
*/
|
||||||
|
private array $cmd = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ContainerInspect
|
* @var ContainerInspect
|
||||||
*/
|
*/
|
||||||
@@ -68,6 +74,13 @@ class Container
|
|||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withHostname(string $hostname): self
|
||||||
|
{
|
||||||
|
$this->hostname = $hostname;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function withEntryPoint(string $entryPoint): self
|
public function withEntryPoint(string $entryPoint): self
|
||||||
{
|
{
|
||||||
$this->entryPoint = $entryPoint;
|
$this->entryPoint = $entryPoint;
|
||||||
@@ -104,6 +117,13 @@ class Container
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withCmd(array $cmd): self
|
||||||
|
{
|
||||||
|
$this->cmd = $cmd;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function withMount(string $localPath, string $containerPath): self
|
public function withMount(string $localPath, string $containerPath): self
|
||||||
{
|
{
|
||||||
$this->mounts[] = '-v';
|
$this->mounts[] = '-v';
|
||||||
@@ -166,6 +186,11 @@ class Container
|
|||||||
$params[] = $this->network;
|
$params[] = $this->network;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->hostname !== null) {
|
||||||
|
$params[] = '--hostname';
|
||||||
|
$params[] = $this->hostname;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->entryPoint !== null) {
|
if ($this->entryPoint !== null) {
|
||||||
$params[] = '--entrypoint';
|
$params[] = '--entrypoint';
|
||||||
$params[] = $this->entryPoint;
|
$params[] = $this->entryPoint;
|
||||||
@@ -177,6 +202,10 @@ class Container
|
|||||||
|
|
||||||
$params[] = $this->image;
|
$params[] = $this->image;
|
||||||
|
|
||||||
|
if (count($this->cmd) > 0) {
|
||||||
|
array_push($params, ...$this->cmd);
|
||||||
|
}
|
||||||
|
|
||||||
$this->process = new Process($params);
|
$this->process = new Process($params);
|
||||||
$this->process->mustRun();
|
$this->process->mustRun();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user