testcontainers/testcontainers-java · warning
Unable to read Dockerfile at path
Error message
Unable to read Dockerfile at path {} What it means
ParsedDockerfile.read() calls Files.readAllLines on the Dockerfile; if reading throws IOException (e.g. permission problems, the file disappearing, or it is a directory), it logs this warning and returns an empty dependency list. The image build continues but dependency pre-pulling is skipped.
Solutions
- Check filesystem permissions on the Dockerfile (chmod/chown) so the test JVM can read it
- Confirm the path is a regular file, not a directory
- Re-run the build; if a race with deletion, ensure nothing deletes the Dockerfile during the test
Example fix
// before
new ImageFromDockerfile().withDockerfile(Paths.get("/docker/dir"))
// after
Path p = Paths.get("/docker/Dockerfile");
if (!Files.isRegularFile(p) || !Files.isReadable(p)) throw new IllegalStateException("unreadable: " + p);
new ImageFromDockerfile().withDockerfile(p); Defensive patterns
Strategy: validation
Validate before calling
Path p = Paths.get(path);
if (!Files.isRegularFile(p) || !Files.isReadable(p)) {
throw new IllegalStateException("Dockerfile unreadable: " + p);
} Try / catch
try {
Files.readAllLines(dockerfile);
} catch (IOException e) {
throw new UncheckedIOException("Cannot read Dockerfile: " + dockerfile, e);
} Prevention
- Check permissions on mounted volumes in CI
- Don't delete Dockerfiles while tests run
- Verify the path is a file, not a directory
When it happens
Trigger: Files.readAllLines(dockerFilePath) throws IOException inside read(), called from the ParsedDockerfile constructor during ImageFromDockerfile.resolve().
Common situations: File deleted between exists() check and read (race); read permission denied; path is actually a directory; filesystem/I/O errors in CI containers with limited mounts.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Tried to parse Dockerfile at path
- Could not load classpath init script
- Could not load classpath init script
- HTTP response code was
- Response: did not match predicate
AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12).
Data as JSON: /api/errors/fe38222b4abd00c0.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/testcontainers/images/ParsedDockerfile.java:54
this.dependencyImageNames = parse(read());
}
@VisibleForTesting
ParsedDockerfile(List<String> lines) {
this.dockerFilePath = Paths.get("dummy.Dockerfile");
this.dependencyImageNames = parse(lines);
}
private List<String> read() {
if (!Files.exists(dockerFilePath)) {
log.warn("Tried to parse Dockerfile at path {} but none was found", dockerFilePath);
return Collections.emptyList();
}
try {
return Files.readAllLines(dockerFilePath);
} catch (IOException e) {
log.warn("Unable to read Dockerfile at path {}", dockerFilePath, e);
return Collections.emptyList();
}
}
private Set<String> parse(List<String> lines) {
Set<String> imageNames = lines
.stream()
.map(FROM_LINE_PATTERN::matcher)
.filter(Matcher::matches)
.map(matcher -> matcher.group("image"))
.collect(Collectors.toSet());
if (!imageNames.isEmpty()) {
log.debug("Found dependency images in Dockerfile {}: {}", dockerFilePath, imageNames);
}
return imageNames;
}
}View on GitHub (pinned to 8e549514e3)