When deploying, I was getting a “database does not exist” error. Therefore made it manually:
sqlite3 /var/lib/dokku/data/storage/myapp/db.sqlite3 "
PRAGMA journal_mode = WAL;
PRAGMA auto_vacuum = INCREMENTAL;
PRAGMA page_size = 4096;
PRAGMA wal_autocheckpoint = 1000;
VACUUM;"
# P.S I executed this as root, for better or worse...
However, on another deployment attempt the app still couldn’t connect to this database or run migrations. This time, the error is different:
** (RuntimeError) connect raised MatchError exception. The exception details are hidden, as they may contain sensitive data such as database credentials. You may set :show_sensitive_data_on_connection_error to true when starting your connection if you wish to see all of the details
(exqlite 0.33.1) lib/exqlite/connection.ex:396: Exqlite.Connection.get_pragma/2
(exqlite 0.33.1) lib/exqlite/connection.ex:405: Exqlite.Connection.maybe_set_pragma/3
(exqlite 0.33.1) lib/exqlite/connection.ex:551: Exqlite.Connection.do_connect/2
(db_connection 2.8.1) lib/db_connection/connection.ex:79: DBConnection.Connection.handle_event/4
I have set show_sensitive_data_on_connection_error to true in runtime.exs, just like it suggested in the error message, and can now see the actual error:
** (MatchError) no match of right hand side value:
{:error, "attempt to write a readonly database"}
It’s because the user inside the container is not root (good practice). I imagine you have nothing important there yet, so my suggestion is that you delete the file (as root) and recreate from inside the container (as the correct user).
E.g. with mix ecto.setup
(Typing on mobile off the top of my head, there can be mistakes)
I deleted the SQLite file and added database creation to release.ex:
def migrate do
load_app()
# This is what `mix ecto.create` does internally:
opts = Application.get_env(:myapp, MyApp.Repo)
MyApp.Repo.__adapter__().storage_up(opts)
# ....
But, it still couldn’t access. So I added a touch command in app.json (for Dokku)
This makes me think the container is somehow completely immutable at build time. I’ll dive deeper into Dokku documentation, and potentially try using buildpacks instead of Dockerfile.
Correcting a small mistake in my previous post – there’s no --chown uid:gid, but instead use --chown false and then manually chown the directory as needed: