Starting a blog with ghost.io running in docker behind haproxy

I'm currently reworking some of my infrastructure and feel the need to take notes on what I'm doing. This is going to be my technical blog where I take those notes. If I'm the only reader it still serves a purpose.

I once had a tech-blog over at posterous which just disappeared when twitter bought them. Not going to let that happen again, so this time I'm going to host it myself.

This blog is served by a ghost instance running on my wardrobe server. See ghost.io.

To startup this blog I did the following:

On my ReadyNAS (RAID 1) I created a new folder shared with NFS simply called "ghost" - shared only to 10.0.1.20 which is my main server. This by clicketiclicking.

I want my data to live on the NAS which I consider "my safe zone" while my actual main server should be replaceable.

On my main server I first mounted it on /var/lib/ghost:

sudo mount -t nfs 10.0.1.30:/raiden/ghost /var/lib/ghost

and in /etc/fstab:

10.0.1.30:/raiden/ghost   /var/lib/ghost   nfs    auto  0  0

Then I started ghost as a docker container:

sudo docker run -d --name blog.woodenstake.se -e NODE_ENV=production -p 2368:2368 -v /var/lib/ghost:/var/lib/ghost ghost

The above means:

  • -d run in daemon mode (not foreground)
  • --name blog.woodenstake.se give it a name for future reference
  • -e NODE_ENV=production an environment variable that ghost uses to run in production mode
  • -p 2368:2368 map port 2386 in the host to 2368 on the container. 2368 is simply ghost's standard port.
  • -v /var/lib/ghost:/var/lib/ghost map the folder path /var/lib/ghost on the host (where I mounted my share) to the path /var/lib/ghost on the container (which is the standard place).
  • ghost is simply the name of the docker image I want to run: https://hub.docker.com/_/ghost/

In my haproxy config I added a simple backend:

frontend
   acl host_blog hdr(host) -i blog.woodenstake.se
   ...
   use_backend ghost if host_blog
   ...
backend ghost
    mode http
    option forwardfor
    http-request set-header X-Forwarded-Port %[dst_port]
    http-request add-header X-Forwarded-Proto https if { ssl_fc }
    option httpchk HEAD / HTTP/1.1\r\nHost:localhost
    server ghost_docker 127.0.0.1:2368

Soft reload:

sudo service haproxy reload

I then fixed up the ghost config /var/lib/ghost/config.js:

config = {
    // ### Production
    // When running Ghost in the wild, use the production environment.
    // Configure your URL and mail settings here
    production: {
        url: 'http://blog.woodenstake.se',
        mail: {
              transport: 'SMTP',
              options: {
                  service: 'Mailgun',
                  auth: {
                      user: 'postmaster@sandboxbxxx.mailgun.org', // mailgun username
                      pass: 'xx'  // mailgun password
                  }
              }
          },
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(process.env.GHOST_CONTENT, '/data/ghost.db')
            },
            debug: false
        },

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

        paths: {
            contentPath: path.join(process.env.GHOST_CONTENT, '/')
        }
    },

and reloaded my ghost instance:

sudo docker reload blog.woodenstake.se

And then I headed here to write this up :)


Update:

Just did an update from 0.6-something to latest 0.7-something to 0.11-something. Just did a snapshot of content on nas and then:

sudo docker stop blog.woodenstake.se
sudo docker rm blog.woodenstake.se
sudo docker pull ghost
sudo docker run -d --restart unless-stopped --name blog.woodenstake.se -e NODE_ENV=production -p 2368:2368 -v /var/lib/ghost:/var/lib/ghost ghost  

Maybe this is helpful for someone, probably not :)

I'm mainly going to use this blog to write down my technical work on stuff that is otherwise hard to track and feel a sense of progress on.

Next up will probably be describing moving from nginx to haproxy for my proxying needs. Stay tuned!