{"record":{"id":"a7a827d3e72699d7","repo":"testcontainers/testcontainers-java","slug":"exception-while-trying-to-create-temp-directory-a7a827","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/selenium/BrowserWebDriverContainer.java","lineNumber":134,"sourceCode":"    protected Set<Integer> getLivenessCheckPorts() {\n        Integer seleniumPort = getMappedPort(SELENIUM_PORT);\n        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        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        String timeZone = System.getProperty(\"user.timezone\");\n\n        if (timeZone == null || timeZone.isEmpty()) {\n            timeZone = \"Etc/UTC\";","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/selenium/src/main/java/org/testcontainers/selenium/BrowserWebDriverContainer.java#L116-L152","documentation":"In the newer org.testcontainers.selenium.BrowserWebDriverContainer.configure(), when no VNC recording directory was supplied, a temp directory is created with Files.createTempDirectory. An IOException there is logged and rethrown as ContainerLaunchException 'Exception while trying to create temp directory', failing container start.","triggerScenarios":"Starting org.testcontainers.selenium.BrowserWebDriverContainer with recording enabled but without withRecordingDirectory when the temp directory cannot be created (unwritable/full java.io.tmpdir).","commonSituations":"Read-only or full /tmp in CI, custom -Djava.io.tmpdir to a missing path, sandboxed/SELinux-restricted build agents.","solutions":["Call withRecordingDirectory(File) with a known-writable path before starting the container.","Check/fix the java.io.tmpdir system property and directory permissions.","Free disk space on the agent or point TMPDIR to a larger volume.","Catch ContainerLaunchException in start-up helper code to record the underlying IOException."],"exampleFix":"// before\nBrowserWebDriverContainer container = new BrowserWebDriverContainer(\"selenium/standalone-chrome:4.9.0\");\n// after\nBrowserWebDriverContainer container = new BrowserWebDriverContainer(\"selenium/standalone-chrome:4.9.0\")\n    .withRecordingDirectory(new File(\"build/vnc-recordings\"));","handlingStrategy":"validation","validationCode":"File vncDir = new File(\"build/vnc-recordings\");\nif (!vncDir.exists() && !vncDir.mkdirs()) throw new IllegalStateException(\"Cannot create \" + vncDir);\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    throw new IllegalStateException(\"Set withRecordingDirectory() or fix temp dir permissions\", e); }\n  throw e;\n}","preventionTips":["Explicitly configure the recording directory in test bootstrap","Verify tmpdir writability in CI setup scripts","Monitor disk space on build agents"],"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"}