{"record":{"id":"067bdf02069b652a","repo":"testcontainers/testcontainers-java","slug":"exception-while-trying-to-create-temp-directory","errorCode":null,"errorMessage":"Exception while trying to create temp directory","messagePattern":"Exception while trying to create temp directory","errorType":"exception","errorClass":"ContainerLaunchException","httpStatus":null,"severity":"error","filePath":"modules/selenium/src/main/java/org/testcontainers/containers/BrowserWebDriverContainer.java","lineNumber":179,"sourceCode":"        if (recordingMode == VncRecordingMode.SKIP) {\n            return ImmutableSet.of(seleniumPort);\n        } else {\n            return ImmutableSet.of(seleniumPort, getMappedPort(VNC_PORT));\n        }\n    }\n\n    @Override\n    protected void configure() {\n        String seleniumVersion = SeleniumUtils.determineClasspathSeleniumVersion();\n\n        if (recordingMode != VncRecordingMode.SKIP) {\n            if (vncRecordingDirectory == null) {\n                try {\n                    vncRecordingDirectory = Files.createTempDirectory(TC_TEMP_DIR_PREFIX).toFile();\n                } catch (IOException e) {\n                    // should never happen as per javadoc, since we use valid prefix\n                    logger().error(\"Exception while trying to create temp directory\", e);\n                    throw new ContainerLaunchException(\"Exception while trying to create temp directory\", e);\n                }\n            }\n\n            if (getNetwork() == null) {\n                withNetwork(Network.SHARED);\n            }\n\n            vncRecordingContainer =\n                new VncRecordingContainer(this)\n                    .withVncPassword(DEFAULT_PASSWORD)\n                    .withVncPort(VNC_PORT)\n                    .withVideoFormat(recordingFormat);\n        }\n\n        if (customImageName != null) {\n            customImageName.assertCompatibleWith(COMPATIBLE_IMAGES);\n            super.setDockerImageName(customImageName.asCanonicalNameString());\n        } else {","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/selenium/src/main/java/org/testcontainers/containers/BrowserWebDriverContainer.java#L161-L197","documentation":"During BrowserWebDriverContainer.configure(), if no VNC recording directory was set, Testcontainers creates a temp directory via Files.createTempDirectory. If that fails with an IOException, it logs the error and rethrows as ContainerLaunchException with this message, aborting container startup.","triggerScenarios":"Calling withRecordingFileFactory/starting a BrowserWebDriverContainer (deprecated module) without withRecordingDirectory when java.io.tmpdir is unwritable, full, or a security manager blocks temp file creation.","commonSituations":"Read-only /tmp in CI containers, disk-full build agents, custom -Djava.io.tmpdir pointing to a non-existent or permission-restricted path, SELinux/AppArmor restrictions.","solutions":["Call withRecordingDirectory(new File(\"/some/writable/path\")) explicitly so temp creation is skipped.","Verify java.io.tmpdir points to an existing, writable directory; set -Djava.io.tmpdir=/tmp if misconfigured.","Free disk space / fix permissions on the temp directory in the CI environment.","Migrate to the newer org.testcontainers.selenium.BrowserWebDriverContainer (Selenium module) which has the same guard — the fix applies identically.","Catch ContainerLaunchException around container.start() to surface the cause IOException in test diagnostics."],"exampleFix":"// before\nBrowserWebDriverContainer container = new BrowserWebDriverContainer()\n    .withRecordingFileFactory(...); // no directory set, relies on /tmp\n// after\nBrowserWebDriverContainer container = new BrowserWebDriverContainer()\n    .withRecordingDirectory(new File(\"/tmp/vnc-recordings\"))\n    .withRecordingFileFactory(...);","handlingStrategy":"validation","validationCode":"File vncDir = new File(System.getProperty(\"java.io.tmpdir\"), \"vnc-recordings\");\nif (!vncDir.canWrite() && !vncDir.mkdirs()) {\n  throw new IllegalStateException(\"Cannot write VNC recording dir: \" + vncDir);\n}\ncontainer.withRecordingDirectory(vncDir);","typeGuard":null,"tryCatchPattern":"try {\n  container.start();\n} catch (ContainerLaunchException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"create temp directory\")) {\n    logger.error(\"Temp dir creation failed; check java.io.tmpdir permissions/disk space\", e.getCause()); }\n  throw e;\n}","preventionTips":["Always set withRecordingDirectory explicitly in CI","Keep java.io.tmpdir writable and monitored for disk space","Point TMPDIR at a dedicated build-agent volume"],"tags":["selenium","temp-directory","io","container-launch"],"backgroundTag":"file-write-failed","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}