As first post for this new tech blog, I am going to introduce you on how to install Ghost on you very own server, with Docker.

Introduction

I always create a start.sh for each container I want to start, with all the properties in place. This allow me to backup with git, all my containers configuration scripts.

Folder structure

mkdir starters/ghost && cd $_
mkdir data && touch config.js start.sh
chmod +x start.sh

config.js

This file contains the needed configurations for Ghost, like email and the most important, the host. If you need more details, check this.

Be sure to change mail.options.auth.pass and url fields.

// # Ghost Configuration
// Setup your Ghost install for various [environments](http://support.ghost.org/config/#about-environments).

// Ghost runs in `development` mode by default. Full documentation can be found at http://support.ghost.org/config/

var path = require('path'), config;

config = {
    // ### Production
    // When running Ghost in the wild, use the production environment.
    // Configure your URL and mail settings here
    production: {
        url: 'http://daniele.brugnara.me',
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(process.env.GHOST_CONTENT, '/data/ghost.db')
            },
            debug: false
        },

        server: {
            host: '0.0.0.0',
            port: '2368'
        },

        mail: {
              transport: 'SMTP',
              options: {
                  service: 'Mailgun',
                  auth: {
                      user: 'postmaster@brugnara.me', // mailgun username
                      pass: '<password here>'  // mailgun password
                  }
              }
        },
    }
};

module.exports = config;

start.sh

Put the following script in your config.js.

replace the port 8080 with the one you want use. do the very same for the --name

docker run -d \
  --restart=always \
  -v $PWD/data:/var/lib/ghost/data \
  -v $PWD/config.js:/var/lib/ghost/config.js \
  -p 8080:2368 \
  --name daniele.brugnara.me \
  ghost:latest \
  /bin/bash -c 'npm start --production'

first run

simple as

./start.sh

Check everything is working as expected:

docker logs -f daniele.brugnara.me

> ghost@0.11.4 start /usr/src/ghost
> node index

Ghost is running in production...
Your blog is now available on http://daniele.brugnara.me
Ctrl+C to shut down

backup your blog

You can do daily backup the data folder, which contains the ghost.db sqlite database file.

nginx

The last thing to do, is to let your Nginx proxy the requests to the backend. This is a simple configuration file you will put in your /etc/nginx/sites-available/yourblog.domain.com. Remember to set server_name with your domain and to set the right port in proxy_pass

server {
  listen                *:80;

  server_name           daniele.brugnara.me;

  access_log            /var/log/nginx/blog.access.log;
  error_log             /var/log/nginx/blog.error.log;

  location / {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection 'upgrade';
    proxy_set_header X-Forwarded-For $remote_addr;
  }
}

Now go to /etc/nginx/sites-enabled/ and do

ln -s ../sites-available/yourblog.domain.com yourblog.domain.com
/etx/init.d/nginx restart

DNS

If not already done, configure your DNS to point to the server' public IP.