redis/node-redis · error · Error
Failed to read ${filePath} from container: ${stderr}
Error message
Failed to read ${filePath} from container: ${stderr} What it means
readFileFromContainer runs `docker exec <id> cat <filePath>` and throws when stderr is non-empty. It is used internally by loadTlsCertificates to extract ca.crt, <cert>.crt, and <cert>.key from a running Redis container into memory. Any stderr from the exec aborts the read.
Source
Thrown at packages/test-utils/lib/dockers.ts:264
/**
* Reads a file from a Docker container directly into memory
* @param dockerId - The Docker container ID
* @param filePath - Path to the file inside the container
* @returns Buffer containing the file contents
*/
async function readFileFromContainer(
dockerId: string,
filePath: string,
): Promise<Buffer> {
const { stdout, stderr } = await execAsync("docker", [
"exec",
dockerId,
"cat",
filePath,
]);
if (stderr) {
throw new Error(`Failed to read ${filePath} from container: ${stderr}`);
}
return Buffer.from(stdout);
}
/**
* Loads TLS certificates from a running Docker container into memory
* @param dockerId - The Docker container ID
* @param certName - The certificate name (used for client cert/key naming)
* @returns TlsCertificates object with ca, cert, and key buffers
*/
async function loadTlsCertificates(
dockerId: string,
certName: string,
): Promise<TlsCertificates> {
const [ca, cert, key] = await Promise.all([
readFileFromContainer(dockerId, `${DEFAULT_TLS_PATH}/ca.crt`),
readFileFromContainer(dockerId, `${DEFAULT_TLS_PATH}/${certName}.crt`),
readFileFromContainer(dockerId, `${DEFAULT_TLS_PATH}/${certName}.key`),View on GitHub (pinned to 90fd0652bc)
Solutions
- Exec into the container to inspect the path: docker exec <id> ls -l /redis/work/tls
- Ensure waitForTlsCertificates completed successfully before calling loadTlsCertificates
- Check the container is still running: docker ps --filter id=<id>
Example fix
# before — file missing, cat writes to stderr # Error: Failed to read /redis/work/tls/client.crt from container: cat: ...: No such file # after — verify the file exists first docker exec <id> ls -l /redis/work/tls/ # wait for cert generation, then retry
Defensive patterns
Strategy: validation
Validate before calling
async function fileExistsInContainer(dockerId: string, filePath: string): Promise<boolean> {
try {
await execAsync('docker', ['exec', dockerId, 'test', '-f', filePath]);
return true;
} catch {
return false;
}
} Try / catch
try {
const buf = await readFileFromContainer(dockerId, filePath);
} catch (e) {
if (e instanceof Error && /Failed to read/.test(e.message)) {
}
throw e;
} Prevention
- Always call waitForTlsCertificates before loadTlsCertificates so files exist
- Verify the cert path layout matches the image version before reading
- Log the container id alongside the failure so a developer can docker exec into it
When it happens
Trigger: The TLS cert file does not yet exist at the expected path (/redis/work/tls/<file>); the container exited before the cat; the path is wrong for the image's TLS layout; permission denied reading the key file.
Common situations: Calling loadTlsCertificates before the container's cert-generation step finished; image version that stores certs under a different directory; container crashed during startup.
Related errors
- TLS certificates not available after ${maxWaitMs}ms
- Config file not found at path: ${path}
- All ports are in use
- docker run error - ${stderr}
- docker rm error - ${stderr}
AI-assisted analysis of redis/node-redis@90fd0652bc (2026-08-11).
Data as JSON: /api/errors/b9f5b731bf03f739.
Report an issue: GitHub.