I've been wanting get my personal site back up, as well as write more for a wee while now, and finally got round to taking the plunge after seeing Ghost's incredible new 1.0 features.
Not being one to miss a chance to try new things, I saw this as a good opportunity to use CoreOS and get Ghost running in a container. At its essence CoreOS provides a lightweight operating system designed to support containerised applications. It ships with Docker right out of the box and was super easy to launch on Digital Ocean.
First off, once we've got our server launched, we need to install Docker Compose. We're not doing anything fancy at the moment and only require one container, but I'm using Compose as it allows me to grow my architecture easily from my
docker-compose.yml. I'd ideally like to run this from MySQL in future, so I can make use of Compose to add that to my stack.
Although it ships with Docker, CoreOS doesn't ship with Docker Compose, so we can install that as follows:
sudo su - mkdir -p /opt/bin curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` > /opt/bin/docker-compose chmod +x /opt/bin/docker-compose
You can verify that went as expected with
Great, we now have Compose at our disposal. We're going to want to persist Ghost's data outwith the container, so we don't lose our content on restart, so lets create a directory to map to the container as a volume with
Now for our
docker-compose.yml, where we define services we want to run:
version: '2' services: web: restart: always image: ghost ports: - "80:2368" volumes: - /home/core/ghost/:/var/lib/ghost/content environment: url: http://markprovan.com
Some things to point out from above are
restarttells Compose to restart the container in the event it crashes
portsallows us to map the Ghost server in the container to out servers http port, to serve the site
volumeslets us mount our local folder to the container, to persist content.
urltells Ghost where the site lives, for building links on the site.
We can kick things off by running
docker-compose up -d, the
-d flag telling Docker that this should be run as a daemon, out of process.
Head on over to your server IP/domain name and you should see your blog running!