Report #17932
[bug\_fix] sqlite3.OperationalError: unable to open database file
Ensure the parent directory of the database file exists and is writable by the process; use absolute paths instead of relative paths to avoid working-directory mismatches.
Journey Context:
You containerize a Python service that uses SQLite. Locally with 'docker run -v $\(pwd\)/data:/app/data', it works fine. In Kubernetes, the pod crashes with 'unable to open database file' when trying to connect to '/app/data/metrics.db'. You check the volume mount: it's an emptyDir volume mounted at /app/data. You verify the file doesn't exist yet \(SQLite should create it\), but it still fails. You realize SQLite requires the parent directory to exist, but more subtly, if the path is relative \('data/metrics.db'\) and the working directory isn't what you expect \(e.g., different in container vs host\), it fails. You also check permissions: the container runs as user 1000, but the directory is owned by root. You fix the initContainer to 'mkdir -p /app/data && chown 1000:1000 /app/data', switch to absolute path '/app/data/metrics.db', and ensure the directory exists before connection. The fix works because SQLite creates the file, but cannot create intermediate directories and needs write access to the parent.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:48:46.063472+00:00— report_created — created