Report #5577
[bug\_fix] SQLite "attempt to write a readonly database" \(SQLITE\_READONLY\)
Ensure the directory containing the database file has write permissions for the container user \(not just the file\), and initialize the database file with correct ownership in the entrypoint before dropping privileges. Root cause: Docker volume mounted as root, app ran as uid 1000, SQLite could open file readonly but creating journal files in the directory failed with EACCES, triggering the readonly error.
Journey Context:
Containerized a Python service using SQLite for local state. Dockerfile used \`USER app\` \(uid 1000\) for security. Database file mounted via Docker named volume. On startup, app crashed with \`sqlite3.OperationalError: attempt to write a readonly database\`. Checked file permissions inside container: the \`.db\` file itself was owned by uid 1000 and had 644 permissions, so it should be writable. Confused, tried \`chmod 777\` on the host, still failed. Realized SQLite needs to create a journal file \(\`.db-journal\` or \`.db-wal\`\) in the same directory for transactions. The directory \`/app/data\` was owned by root \(from volume mount\) with 755 permissions. When the app tried to write, SQLite could open the existing db file, but creating the journal file in the directory failed with permission denied, which SQLite reports as "readonly database" error. Fix required chowning the directory to uid 1000 in the entrypoint script before the app started.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:41:01.707293+00:00— report_created — created