mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-12 12:29:56 +00:00
feat: allow publishing ports for containers
This commit is contained in:
@@ -39,6 +39,11 @@ class Container
|
|||||||
*/
|
*/
|
||||||
private array $mounts = [];
|
private array $mounts = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string>
|
||||||
|
*/
|
||||||
|
private array $ports = [];
|
||||||
|
|
||||||
protected function __construct(private string $image)
|
protected function __construct(private string $image)
|
||||||
{
|
{
|
||||||
$this->wait = new WaitForNothing();
|
$this->wait = new WaitForNothing();
|
||||||
@@ -86,6 +91,14 @@ class Container
|
|||||||
return $this;
|
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
|
public function withNetwork(string $network): self
|
||||||
{
|
{
|
||||||
$this->network = $network;
|
$this->network = $network;
|
||||||
@@ -105,6 +118,7 @@ class Container
|
|||||||
'--name',
|
'--name',
|
||||||
$this->id,
|
$this->id,
|
||||||
...$this->mounts,
|
...$this->mounts,
|
||||||
|
...$this->ports,
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($this->env as $name => $value) {
|
foreach ($this->env as $name => $value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user