Setting up your Mailgun in your selfhosted Ghost

If you're hosting your own Ghost blog in a docker container you should to know how to setting up your mail settings with Mailgun, if not I will show you how πŸ‘

Setting up your Mailgun in your selfhosted Ghost
Photo by Joanna Kosinska / Unsplash

In previous posts about Ghost I talked about how to create your own self hosted blog with Ghost blog:

Building your own Blog with Ghost | Docker | Apache2
Hello, if are interested in setting up your own blog for a low cost this post is for you, we will cover how to set your blog up using Ghost + Docker + Apache2, and you will be able to share with the world your amazing ideas, cakes recipes or photos of

Building your own blog with Ghost, Docker and Apache2

And I show you how easy is upgrade your Ghost Docker instance to latest version:

How to upgrade Ghost in docker containers πŸ‘»
How Ghost upgrade in docker container

How to upgrade your Ghost Docker instance

Now I will show you how to setting up your Mailgun account to send emails in your blog.

TL;DR

Do you have a Ghost blog in a Docker container, and do you need to setting up the emails with Mailgun? i will show you how to do it here!

What is Mailgun πŸ€”

Mailgun is a platform that enables you to send, track, and optimize emails effortlessly (it is for free and offers up to 5000 mails per month), perfect companion for you blog.

Prerequisites 🚏

  1. Mailgun API key it is given to you once you create your Sending domain.
  2. SMTP credentials, in Mailgun > Domain settings > SMPT credentials

Add credentials to Ghost in your Docker container

You should to add your Mailgun SMTP credentials to your config.production.json this file will be located in your docker container at /var/lib/ghost/config.production.json you could do it manually by copying the file inside the container with docker cp the copy command provided by docker for this purpose, if you are looking for this kind of solution it looks like:

cp config.production.json <blog_ghost_container_id>:/var/lib/ghost/config.production.json

This works but it is not great as every time you stop your container the file will lost, given the nature of containers.

So let's include this command in your docker-compose file to do it automatically for you each time you run a docker-compose up πŸš€

Lets add a Dockerfile that will copy the file for us:

FROM ghost:5.79.4
WORKDIR /var/lib/ghost
COPY config.production.json ./

now lets modify your docker-compose file to build the image from Dockerfile:

version: '3.1'   
                                                                                                   
services:
                                                                                                   
  ghost:
    image: ghost:5.79.4
    # this line make the image be build from Dockerfile      
    build: ./
    restart: always
    ports:
      - 8080:2368
    volumes:
      - ghost-data:/var/lib/ghost/content
    environment:
      # see https://ghost.org/docs/config/#configuration-options
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: ${MYSQL_PWD}
      database__connection__database: ghost
      url: https://blog.nicoandres.dev

  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_PWD}
    volumes:
      - db-data:/var/lib/mysql

volumes:
  ghost-data:
  db-data:

With the new build: section you are telling to docker to build the image first, so now you need to run docker-compose up -d --build and your config.production.json will be ready for let you send emails πŸ“§ πŸš€

Sources

  • Ghost docs mail section:
Configuration - Adapt your publication to suit your needs
Find out how to configure your Ghost publication or override Ghost’s default behaviour with robust config options, including mail, storage, scheduling and more!