November 26, 2017

Ghost blog setup with Docker

A few months, I mentioned how Nginx and Ghost was setup
That was running version 0.9 of ghost. I finally decided to upgrade to ghost v1 (1.18 at time of writing). Ghost 1.x is described as a major upgrade, with many breaking changes. There is no real upgrade path, so you really need to start a clean new v1 install, and import your existing content.

When I initially tried the migration, it broke badly. With docker, I mounted the config directory from the host, which had the blog data and theme. The theme had broken (due to major version changes), and I could not get blog to come up. But the ain issue was that the config file had changed, and ghost was not reading it, and since I dont ghost as the main domain, but hanging off /blog, all the links were broken.

After struggling for a good few days, I finally got it to work.

This was how I used to run the ghost docker container:

docker run -d -p 4431:2368 --restart-always -v /home/yusufm/gitwork/ghost-data:/var/lib/ghost ghost

And this is how I run it now:

docker run -d --name ghost-v1-13 -p 4431:2368 --restart always -v /home/yusufm/gitwork/ghost-data-v1:/var/lib/ghost/content -e url=http://gcp.hacksaw.co.za/blog/ ghost

which looks like this:

yusufm@hacksaw-1:~/gitwork$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
132bf4c26c5e        ghost               "docker-entrypoint..."   5 seconds ago       Up 3 seconds        0.0.0.0:4431->2368/tcp   ghost-v1-13

The main changes are

  • /var/lib/ghost has changed to /var/lib/ghost/content
  • using environment variables to specifu the URL, which is required if you have a subdomain or part after the main domain name, like /blog

Btw, I now use --name to specify the container name, rather than an auto-generated random container name

These were very helpfull posts:

This is the process I used to run the new ghost version 1.18:

  1. Export your data from the v0 ghost. In the editor, go to Labs, and export to save all data into a single json file. I dont think it exports images though
  2. Get the alpine version ghost:1-alpine. The normal ghost will work as well, alpine is smaller and lightweight
  3. Create a clean directory mount your data. Dont use the existing v0 directory
  4. docker run as above
  5. Ngnix config to send /blog to the docker port
  6. Import your data: from the editor, go the Labs, and import the json file

The bad part is that the config file is in the container, and not on the host, which means its not persistent. But since I only needed to change the URL, and I am doing it in the docker run command, its not too bad.


TODO:
Use the docker compose to specify the config file location