Awesome FOSS Logo
Discover awesome open source software
Launched 🚀🧑‍🚀

Using dockerized Ghost with local SMTP

Categories

Getting a dockerized instance of Ghost to use local SMTP

When handling mail for a ghost instance, the official recommendation of the Ghost team is to use Mailgun. Since I have email set up on the server on which I’m running Ghost, despite the fact that Mailgun offers a pretty good free tier of services, it seems pretty extraneous/unnecessary to use mailgun just to send email from my own server. Of course, this ignores the effort that it takes to set up things like postfix, dovecot, and opendkim, but I digress.

Below is the account of what it took for me to find out how to use a local SMTP server properly with a dockerized instance of Ghost.

tldr; Use alpine-ghost, mount it to a local volume so you can alter config (and have changes persist), and make sure you get the docker host IP to pass to Ghost.

Issues

Site URL configuration

Maybe I should have exepected it since it’s so common that there’s a blog post telling you why your site url is wrong, but I messed up my site URL config. That blog post has good details on the issue, so I’d suggest you read on there.

Getting the right IP to feed to config.js

The IP for the regular machine from inside a container is known as the Docker host IP. This is, of course, the IP that the container needs to know to access services running on the host. I used two old trusty lines of bash to get the DOCKER_HOST_IP for use in my deployment script:

DOCKER_HOST_IP=`ip route | grep docker0 | awk '{print $9}'`;
echo  "Resolved DOCKER_HOST_IP TO: [$DOCKER_HOST_IP]..."

Creating a user/password for the ghost user

It’s a good idea to create a user/password for the account that’s going to be sending emails out using ghost. With the way postfix is configured on the system, I still needed to provide a username and password to send mail on localhost.