How to configure Ghost in a Docker container and setup email
When setting up a new Portainer instance, the age old saying starts to drift back into my mind: "Well, it works on my machine..." And as I set up my networks inside Portainer and begin setting up other containers, I brush that thought away until I run into a problem. How do you get ghost to work correctly in a Docker container? It seems so simple to install it on the host machine, but it feels 10x more complicated in the docker install.
Problem #1: Database
Sometime last year, the Ghost docker container was updated to use a new database in production: MySQL 8. All of us with SQLite databases connected to our Ghost containers couldn't even get them to boot. Here is a fix to allow the continued use of SQLite as a database for the official Ghost docker instance.
Here is a link to download the picture if you need to enlarge it:
These variables ensure that Ghost will run using a SQLite database as a backend.
Problem #2: Email
There are two types of email that are used in Ghost. The first is the newsletter mass email service that is configured via the Ghost control panel that requires Mailgun. You can find your Mailgun domain and key following the links presented in the control panel pictured below.
The second type of email is transactional email. This is where the challenging part comes in...
When signing up to become a newsletter subscriber, you are emailed a special link with a sign-up button and once you click that you are all set. This method of email is the transactional email service, which requires Ghost to send very few emails comparatively but they need to be delivered quickly and reliably. Usually, these parameters are setup in the config.production.json file, however in Docker, we alter these variables in a different way.
In the environmental variables file (or the Portainer GUI) there is also a way to change these values. The picture below shows the needed environmental variables for the transactional email service to be used. FYI: in the variables names there are 2 underscores between each name!
Like before, here is a download in case the image is too small:
The transport, host, port, and secure settings can be changed to use whatever service you would like. I have tested it with AWS SES, SendGrid, and Mailgun and all 3 services work. For the mail from address, ensure to change it to your correct contact information but using the same syntax and lettering that I have used to ensure that it shows up correctly on the receiver's email account. Finally, acquire the correct username and password from your mail provider and paste them into the variable value fields, restart Ghost, and you should be off to the races!
If this does not work, carefully check your variables names, values, and your active credentials with your mail provider. This setup is a pain in the beginning, but perfecting this allows you complete control over Ghost in the docker container while providing a full experience for your readers.
Don't believe it works? These are screenshots from my setup. Try it now and sign up for notifications when I post a new article! Thanks for reading, and I hope this helps you fix your Ghost email woes!