Lab - Install Ghost CMS using Docker and NPM

Preparation

  • Assume Docker and Docker Compose is in place - see here.
  • Assume Nginx Proxy Manager is in place - see here.

Installation

First create a folder, next to the NPM folder, although other places are also OK:

mkdir myghost
cd myghost

Create the following docker-compose.yaml in the folder:

networks:
  mynet:
    name: mynet
    external: true

services:
  myblog:
    image: ghost:5-alpine
    restart: unless-stopped
    expose:
      - 2368
    environment:
      database__client: "sqlite3"
      database__connection__filename: "content/data/ghost.db"
      database__useNullAsDefault: "true"
      database__debug: "false"
      url: https://myblog.example.com
    volumes:
      - ./data:/var/lib/ghost/content
    networks:
      - mynet

Note that

  • Assume the network mynet has been declared in the NPM configuration
  • This setup use SQLite3 for simplicity, but Ghost has indicated that MySQL 8 is the only officially supported database for production
  • The configuration skips SMTP setup, which is required if user login (subscription) is needed.

Launch Ghost and see if it runs OK:

docker compose up -d && docker compose logs -f

Nginx Proxy Manager

The configuration above assumes myblog.example.com has been created and bind to this machine where the NPM is running. Create a host proxy with NPM and see if you can access the newly created Ghost site via HTTPS: https://myblog.example.com.

Initialization

Head to the admin location at https://myblog.example.com/ghost, and create the admin account as prompted.

Afterwards you can create posts, publish them, and see how they look from the home page.

Full Setup with MySQL and SMTP

According to the official site https://ghost.org/docs/install/docker/ which has link to https://hub.docker.com/_/ghost/ that contains a more extensive configuration file for production use. The file docker-compose.yaml is based on the version:

networks:
  mynet:
    name: mynet
    external: true

services:
  myblog:
    image: ghost:5-alpine
    restart: unless-stopped
    expose:
      - 2368
    environment:
      # see https://ghost.org/docs/config/#configuration-options
      database__client: "mysql"
      database__connection__host: "mysqldb"
      database__connection__user: "root"
      database__connection__password: ${MYSQL_ROOT_PASS}
      database__connection__database: "myblog"
      url: https://myblog.example.com
      NODE_ENV: production
      mail__transport: SMTP
      mail__from: ${SMTP_FROM}
      mail__options__service: ${SMTP_SERVICE}
      mail__options__host: ${SMTP_HOST}
      mail__options__port: ${SMTP_PORT}
      mail__options__from: ${SMTP_FROM}
      mail__options__auth__user: ${SMTP_AUTH_USER}
      mail__options__auth__pass: ${SMTP_AUTH_PASS}
    env_file:
      - .env
    volumes:
      - myblog_vol:/var/lib/ghost/content
    networks:
      - mynet

  mysqldb:
    image: mysql:8.0
    cap_add:
      - SYS_NICE
    restart: unless-stopped
    environment:
      - MYSQL_DATABASE=myblog
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASS}
    env_file:
      - .env
    volumes:
      - mysql_vol:/var/lib/mysql
    networks:
      - mynet

volumes:
  myblog_vol:
    driver: local
  mysql_vol:
    driver: local

For the configuration to work, create file .env containing the following environment variables:

MYSQL_ROOT_PASS=some_good_password

SMTP_SERVICE=Gmail
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_FROM=noreply@example.com
SMTP_AUTH_USER=support@example.com
SMTP_AUTH_PASS=xxxx xxxx xxxx xxxx

Note that for quick exercise, the example SMTP setup above uses Google's app passwords for personal account.

  • Basically you need to sign in into your google account, then in the Security section, enable 2-Step Verification.
  • After that you can visit https://myaccount.google.com/apppasswords to generate a password with proper name for this use case.
  • Make sure your VPS provider does not block out-going traffic to SMTP related ports.

You can use another service, such as Mailgun's offer as suggested by Ghost, for more serious purpose. Other e-mail service providers are also possible.

Member Subscription

To test the SMTP setup, hence the subscription function, you can add yourself as a member for testing from the admin panel, or simply subscribe in the front page with some e-mail account you have.


To be continued...