The blog that you're reading is powered by Ghost in a Docker container, running with an SQLite database.
Sometime last year in 2022, Ghost made a major update and announced that the only supported database would be MySQL, and that SQLite is no longer supported.
For major sites and blogs, MySQL is certainly a sensible option. But for small-scale projects and hobbyist sites like mine, it's just overkill. Anyway, when I unknowingly upgraded from Ghost Docker version 5.8.3 to 5.9, it broke my site and threw an error of "error: connect econnrefused 127.0.0.1:3306", basically saying that it can't connect to the MySQL Database that it was expecting.
Since then, for the last 9 months or so, I held my Ghost Docker image at version 5.8.3 simply because I didn't want to bother with converting an SQLite DB to MySQL, or exporting and reimporting the data to a fresh install, I just left it - why change it if it works perfectly fine, right? (Also, I'm lazy.)
Today, due to various security vulnerabilities that have since been found, I put on my big boy pants and decided I need to figure out how to get the latest version of Ghost with the least amount of effort, and here we are. This is a walkthrough of how I upgraded Ghost and kept the original SQLite database.
Spoiler alert: it was easier than I expected.
How to Upgrade to Ghost Docker v5.9 onward whilst keeping SQLite as the default database
Step 1: Backup Your Current Installation
Before upgrading to a new version of Ghost Docker, make sure to backup your current installation. This ensures that you have a fallback option in case something goes wrong during the upgrade process. I won't note down how to backup, there are too many options to write about.
Step 2: Update Your Docker Compose File
Next, you'll need to update your Docker Compose file to use the new version of Ghost Docker.
Open your Docker Compose file and update the Ghost image version to
ghost:5.9 (or later). You can do this by changing the following line:
image: ghost:5.9 (or later)
Save the changes to your Docker Compose file.
Step 3: Start Your Container with the SQLite Database
By default, Ghost Docker version 5.9 onwards uses MySQL as the default database. To continue using SQLite, you'll need to start your container with some new environment variables to specify the database connection details.
Add the following lines to your Docker Compose file:
environment: - database__client=sqlite3 - database__connection__filename=/var/lib/ghost/content/data/ghost.db
This sets the database client to SQLite and specifies the path to the SQLite database file.
Step 4: Start Your Ghost Docker Container
Once you've made these changes to your Docker Compose file, you can start your Ghost Docker container with the following command:
docker-compose up -d
This will start your container in the background.
Step 5: Verify Your Ghost Docker Installation
Finally, verify that your Ghost Docker installation is working correctly by visiting your website in a web browser. You should see your website running on the latest version of Ghost.
This method let's me keep my existing SQLite database whilst using the latest version of Ghost which has the latest security patches, however as it is not officially supported, I'm aware that I may need to revisit this again in the future and figure out how to migrate to MySQL (hopefully Ghost will provide something to easily migrate the data).