From 90dc166fe600c4c76f35da5e1890756c8cc3eb01 Mon Sep 17 00:00:00 2001 From: Andreas Wunderwald Date: Thu, 21 May 2026 09:26:34 +0200 Subject: [PATCH 1/2] feat: add support for tmpfs mounts in GenericContainer --- src/Container/GenericContainer.php | 16 +++++++++++++++- src/Container/TestContainer.php | 2 ++ tests/Integration/GenericContainerTest.php | 13 +++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Container/GenericContainer.php b/src/Container/GenericContainer.php index 5a9d113..45d3998 100644 --- a/src/Container/GenericContainer.php +++ b/src/Container/GenericContainer.php @@ -96,6 +96,9 @@ class GenericContainer implements TestContainer */ protected array $mounts = []; + /** @var array */ + protected array $tmpfs = []; + /** @var array List of exposed ports in the format ['8080/tcp'] */ protected array $exposedPorts = []; @@ -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 @@ -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; } @@ -479,6 +489,10 @@ protected function createHostConfig(): ?HostConfig $hostConfig->setMounts($this->mounts); } + if ($this->tmpfs !== []) { + $hostConfig->setTmpfs($this->tmpfs); + } + return $hostConfig; } diff --git a/src/Container/TestContainer.php b/src/Container/TestContainer.php index 43b68ed..5b16baf 100644 --- a/src/Container/TestContainer.php +++ b/src/Container/TestContainer.php @@ -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; + public function withName(string $name): static; public function withNetwork(string $networkName): static; diff --git a/tests/Integration/GenericContainerTest.php b/tests/Integration/GenericContainerTest.php index 0b4188f..0f7eea5 100644 --- a/tests/Integration/GenericContainerTest.php +++ b/tests/Integration/GenericContainerTest.php @@ -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(['cat', '/proc/mounts']); + self::assertStringContainsString('tmpfs /mnt/tmpfs', $result); + + $container->stop(); + } + public function testShouldSetPrivilegedMode(): void { $container = (new GenericContainer('alpine')) From 8e485c252b7e413236f125cf960183254423d115 Mon Sep 17 00:00:00 2001 From: Andreas Wunderwald Date: Thu, 21 May 2026 10:08:42 +0200 Subject: [PATCH 2/2] fix: use stat to verify tmpfs mount type in test Replaces `cat /proc/mounts` with `stat -f -c %T` to reliably check the filesystem type, avoiding issues with large stream output in CI. Co-Authored-By: Claude Opus 4.6 --- tests/Integration/GenericContainerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Integration/GenericContainerTest.php b/tests/Integration/GenericContainerTest.php index 0f7eea5..78afe6e 100644 --- a/tests/Integration/GenericContainerTest.php +++ b/tests/Integration/GenericContainerTest.php @@ -298,8 +298,8 @@ public function testShouldSetTmpfs(): void ->withCommand(['tail', '-f', '/dev/null']) ->start(); - $result = $container->exec(['cat', '/proc/mounts']); - self::assertStringContainsString('tmpfs /mnt/tmpfs', $result); + $result = $container->exec(['stat', '-f', '-c', '%T', '/mnt/tmpfs']); + self::assertSame('tmpfs', $result); $container->stop(); }