/ DevOps

A Ghost blog v1.x in less than 5 minutes with docker-compose (Automated Let's Encrypt - Free SSL/TLS Certificates included)

Comments

What is expected ?

At the end of this tutorial, you will have 4 containers with nginx, let's encrypt, mysql and ghost installed. Your blog will be accessible through HTTPS with ssl certificate generated and renewed automatically.

List of docker images we will use:
Nginx-proxy
Automated Let's Encrypt - SSL-companion
MySQL
Ghost v1.x

Setup

Your Ghost instance will need a dedicated server / VPS - Virtual Private Server (ovh) or a droplet (from Digital Ocean, AWS, etc...) with ubuntu or debian installed. We assume that you have already installed docker and docker-compose.

Create Directories

mkdir -p /docker/ghost/{db/data,nginx,ssl,www}
touch /docker/ghost/docker-compose.yml
chmod 777 -R /docker

Docker-Compose

  1. Open docker-compose.yml with nano editor :
nano /docker/ghost/docker-compose.yml
  1. Copy/Paste this content
version: '2'
services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - /docker/ghost/nginx/vhost.d:/etc/nginx/vhost.d
      - /docker/ghost/nginx/html:/usr/share/nginx/html
      - /docker/ghost/ssl:/etc/nginx/certs:ro
  ssl-companion:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: ssl-companion
    volumes:
      - /docker/ghost/ssl:/etc/nginx/certs:rw
      - /var/run/docker.sock:/var/run/docker.sock:ro
    volumes_from:
      - nginx-proxy
    depends_on:
      - nginx-proxy
  mysql:
    image: mysql:latest
    environment:
      - MYSQL_ROOT_USER=your-mysql_user
      - MYSQL_ROOT_PASSWORD=your-mysql_user_password
      - MYSQL_DATABASE=ghost
    volumes:
      - /docker/ghost/db/data:/var/lib/mysql
    restart: always
  ghost:
    image: ghost:latest
    depends_on:
      - mysql
    ports:
      - 2368
    volumes:
      - /docker/ghost/www:/var/lib/ghost/content
    environment:
      - NODE_ENV=production
      - VIRTUAL_HOST=www.your-domaine.com, your-domaine.com
      - LETSENCRYPT_HOST=www.your-domaine.com, your-domaine.com
      - LETSENCRYPT_EMAIL=your-email@your-domaine.com
      - database__client=mysql
      - database__connection__host=mysql
      - database__connection__user=your-mysql_user
      - database__connection__password=your-mysql_user_password
      - database__connection__database=ghost
      - GHOST_HOST=www.your-domaine.com
      - url=https://www.your-domaine.com
    restart: always
  1. Replace all words beginning with "your-*" with your own settings

Launch your containers

cd /docker/ghost
docker-compose up -d

Once all containers are running, you can go to https://www.your-domaine.com/ghost with your web browser and create your administrator user.

Once finished, shut down containers with this command:

docker-compose down

Redirect http(or https)://your-domaine.com to https(only)://www.your-domaine.com

touch /docker/ghost/nginx/vhost.d/your-domaine.com
nano /docker/ghost/nginx/vhost.d/your-domaine.com

Add these lines:

rewrite ^/(.*)$ https://www.your-domaine.com/$1 permanent;

Ghost folder & file permissions

find /docker/ghost/www -type d -exec chmod 755 {} \;
find /docker/ghost/www -type f -exec chmod 664 {} \;

Restart your containers

cd /docker/ghost
docker-compose up -d

That's it ! You have a new fresh ghost blog.