Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Container/GenericContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class GenericContainer implements TestContainer
*/
protected array $mounts = [];

/** @var array<string, string> */
protected array $tmpfs = [];

/** @var array<string> List of exposed ports in the format ['8080/tcp'] */
protected array $exposedPorts = [];

Expand Down Expand Up @@ -221,6 +224,13 @@ public function withMount(string $localPath, string $containerPath): static
return $this;
}

public function withTmpfs(string $containerPath, string $options = 'rw,noexec'): static
{
$this->tmpfs[$containerPath] = $options;

return $this;
}

/**
* Add ports to be exposed by the Docker container.
* This method accepts multiple inputs: single port, multiple ports, or ports with specific protocols
Expand Down Expand Up @@ -458,7 +468,7 @@ protected function createHostConfig(): ?HostConfig
* the API will throw ContainerCreateBadRequestException: bad parameter.
* Until it will be checked and fixed, we just return null if these properties are not set.
* */
if ($this->exposedPorts === [] && !$this->isPrivileged && $this->mounts === []) {
if ($this->exposedPorts === [] && !$this->isPrivileged && $this->mounts === [] && $this->tmpfs === []) {
return null;
}

Expand All @@ -479,6 +489,10 @@ protected function createHostConfig(): ?HostConfig
$hostConfig->setMounts($this->mounts);
}

if ($this->tmpfs !== []) {
$hostConfig->setTmpfs($this->tmpfs);
}

return $hostConfig;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Container/TestContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public function withLabels(array $labels): static;

public function withMount(string $localPath, string $containerPath): static;

public function withTmpfs(string $containerPath, string $options = 'rw,noexec'): static;
Comment thread
shyim marked this conversation as resolved.

public function withName(string $name): static;

public function withNetwork(string $networkName): static;
Expand Down
13 changes: 13 additions & 0 deletions tests/Integration/GenericContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ public function testShouldSetMount(): void
$container->stop();
}

public function testShouldSetTmpfs(): void
{
$container = (new GenericContainer('alpine'))
->withTmpfs('/mnt/tmpfs')
->withCommand(['tail', '-f', '/dev/null'])
->start();

$result = $container->exec(['stat', '-f', '-c', '%T', '/mnt/tmpfs']);
self::assertSame('tmpfs', $result);

$container->stop();
}

public function testShouldSetPrivilegedMode(): void
{
$container = (new GenericContainer('alpine'))
Expand Down
Loading