Database access error on self hosted nextjs docker container

Hello
As part of teaching myself nextjs, I wrote a small roster app for a group I help manage. It’s mostly mugshot + name and title.
Those are stored in a small better-sqlite3 db located at the root of my project, and accessed when needed through functions stored in a library file.
This works well enough in local, but upon deploying a container image on my self hosted nginx server, I’m getting this on accessing the app:

⨯ TypeError: Cannot read properties of undefined (reading 'id') at h (.next/server/chunks/ssr/_39c43809._.js:12:591) { digest: '2257150320' }
From some cursory research I’ve done, I’m led to thinking that it may be due to the nature of a sqlite db and how it works with a docker container. Is there something I either need to do add in my dockerfile, or do I need to switch to a different type of db altogether?
Thanks in advance.

Thanks for posting, SQLite can work fine in Docker, but this error usually means your DB query returned undefined at runtime (often because the .db file isn’t where the container expects it, or it’s not readable).

A few quick checks that typically pinpoint it:

  1. Confirm the DB file exists in the running container
  • Exec into the container and check the working directory + whether the .db file is present and non-empty.
  1. Watch out for relative paths
    If your code opens the DB via a relative path like ./roster.db, that depends on the container’s cwd. Consider switching to an absolute path (e.g., /data/roster.db) so it’s consistent in all environments.
  2. Persist the DB using a volume (recommended)
    Containers are ephemeral; if you expect the DB to survive redeploys, mount it via a Docker volume (preferred for persistent container data) or a bind mount.
    Docker docs: Volumes are the recommended mechanism for persisting data used by containers. https://docs.docker.com/engine/storage/volumes/
    Bind mounts overview: https://docs.docker.com/engine/storage/bind-mounts/

If you share your Dockerfile (especially if it’s multi-stage) and how you reference the DB path in code, we can point out exactly where the DB file is getting dropped or mislocated.