3 min read

Make SQLite work again with Ghost 5.x on Docker

They'll have to pry SQLite from our cold, dead hands.
Ghost 5.0
The next generation of powerful technology for independent publishers.

With the release of Ghost 5.0 back in May 2022, one of the biggest architectural changes was the announcement that MySQL 8 would be the only database officially supported in production environments. While committing to a full-blown database like MySQL might be a sensible and easy-to-make decision for a larger company or business, for those of us who primarily use Ghost as a hobbyist or small-business/side-gig static blogging platform (ditto on those new Ghost features like paid subscriptions and native commenting), SQLite has been working fine for years. It's easy (no need to configure and maintain a giant MySQL installation), it's still highly performant, and best of all, it's easily backed up - all I need to do is cp -R my ghost directory. And specifically for those of us who like to make life even easier with Docker, the official Docker Ghost image has also shipped with SQLite as the default database for years....until it didn't.

https://github.com/docker-library/ghost/pull/323

Somewhere in the vicinity of the Docker image release for Ghost 5.9, the default database was switched to MySQL. Not a terribly unreasonable idea given that the production default for Ghost 5.x is MySQL, but unfortunately this change broke a lot of people's existing Ghost-on-Docker instances that used the old default sqlite3 setup, as evidenced by the numerous subsequent complaints.

New 5.9.3 Breaks previous version 5 ghost installs · Issue #327 · docker-library/ghost
Error when updating to the new version from a older version that did not use a dedicated database. [2022-08-17 08:55:32] INFO Ctrl+C to shut down [2022-08-17 08:55:32] INFO Ghost server started in ...
Database error upon deployment via Docker
Same issue here as well.

Thankfully, the fix for this is relatively easy, assuming you want to keep using SQLite. Stop and remove your existing Ghost container, then recreate it with the following environment variables:

-e database__client=sqlite3 \
-e database__connection__filename="content/data/ghost.db" \
-e database__useNullAsDefault=true \
-e database__debug=false \

This is consistent with Ghost's officially recommended configuration settings for sqlite3. Assuming that the path to your ghost.db is correct, your Ghost instance should be back up and running shortly!

Caveats

It bears repeating that running Ghost on SQLite in production is officially unsupported, and that this could stop working at any time if future versions of Ghost implement new features or breaking changes that simply won't work with SQLite any more. Indeed, you'll be reminded of this every time you visit the admin panel. However, as Ghost uses knex.js as a database abstraction layer, hopefully this won't happen anytime soon!