Skip to content

Commit

Permalink
Merge pull request #16 from redlahatarbus/main
Browse files Browse the repository at this point in the history
Adding ability to run docker container with hostname and command
  • Loading branch information
shyim authored Aug 17, 2024
2 parents 68a2d6d + b9c1424 commit c75dfad
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,24 @@ 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;

/**
* @var array<string>
*/
private array $cmd = [];

/**
* @var ContainerInspect
*/
Expand Down Expand Up @@ -68,6 +74,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;
Expand Down Expand Up @@ -104,6 +117,13 @@ public function withHealthCheckCommand(string $command, int $healthCheckInterval
return $this;
}

public function withCmd(array $cmd): self

Check failure on line 120 in src/Container/Container.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Method Testcontainers\Container\Container::withCmd() has parameter $cmd with no value type specified in iterable type array.
{
$this->cmd = $cmd;

return $this;
}

public function withMount(string $localPath, string $containerPath): self
{
$this->mounts[] = '-v';
Expand Down Expand Up @@ -166,6 +186,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;
Expand All @@ -177,6 +202,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();

Expand Down

0 comments on commit c75dfad

Please sign in to comment.