Report #69842
[bug\_fix] attempt to write a readonly database
Ensure the SQLite database file, its -wal file, and the containing directory are writable by the process. If running in a container with a read-only root filesystem, mount a writable volume for the database. If the -wal file was created by a different user/UID, delete it or chown it.
Journey Context:
Deployed a Python FastAPI application to a Docker container with a read-only root filesystem for security. The app uses SQLite. On startup, it crashes with "attempt to write a readonly database." Initial investigation checks file permissions on the .db file itself \(chmod 666\), but the error persists. The rabbit hole reveals that SQLite in WAL mode creates a .db-wal file alongside the main database. When the container filesystem is read-only, SQLite cannot create or write to this -wal file, even if the main .db file is on a writable bind mount. Additionally, SQLite needs to create temporary files in the directory for locking. The fix requires mounting a volume that is writable for both the .db and .db-wal files, ensuring the directory itself is writable, or switching the container to allow writes to that specific path. If a .wal file exists from a previous run with different permissions, it must be removed or chowned.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T23:42:49.852650+00:00— report_created — created