A new machine arrives & ghost in a container

The fan-less PC arrived much more quickly than expected! They really tried to exceed expectations by indicating it might take a month and then delivering in about a week! Following that there was the minor issue of getting Ubuntu Server on it via USB. This was pretty painless, following their own instructions. Since the rest of my internal ecosystem was ready for more linux machines, getting it integrated was pretty eas

As with all computers, it needed a name! And I seem to be running out of cats to name computers after! So, since this computer would be used to essentially replace the role of the raspberry pi called diamond-pi
I decided to call it diamond
(original I know!).
Getting everything setup was (as always) trivial using apt
, as was installing docker
and all I needed to recall was to add my user to the docker
group. Pulling the ghost container was also simple, but getting the right settings for it to run, less so!
What was nice, was that out of the box it comes with a default site that shows you are up and running. But obviously I had an existing site (if somewhat limited!) that I wanted to transfer. All the instructions I could find simply indicated that if I mounted my content in the right place all would be good
-v /route/to/content/locally/:/var/lib/ghost/content
So that is what I did! And the container started ... and exited. Humm! Without my content all is OK, with it, less so. I was willing to forgive ghost since I was still running a pretty old version on the pi. I recall a really new feature last time I upgraded that would allow export of the content via JSON. So, instead of mounting my old content, I went and exported it from the old blog, started the new blog afresh and tried to import it ... ouups again. It appears that between beta and v2 (which I am now running!) they changed the format of the JSON. Fortunately the error message indicated that I'd need to import the content into v1, and then export from there. Aghhh!!! But actaully, less aghh than I imagined. There is a v1 ghost docker container ... to the rescue. Pull that, start it, create a dummy account, import the beta content ... yipppee there are all the stories ... and export again. This is looking good.
So now we start up the v2 ghost docker container (with an external mount point needed in a moment), actually create a real user to submit stories as, import the v1 JSON stories (looking good!), set the site front cover, etc. Its beginning to look like a real site. The only thing is, all the content is currently inside the container. How do I get the content outside the container?
docker exec -i ghost /bin/bash
Docker exec to the rescue here! We can now start working inside the container interactively. Recall that mount we put when we started the conatiner (its going to save to the machine /tmp
location). So we simply cp
the content of /var/lib/ghost/content
to the mounted location in the container, which actually makes it available outside. Then we can stop the container (and destroy it), move the content from /tmp
to a more suitable long term location and restart the container cross-mounting that to the right place in the container. And volia, all is working!
What I mean by all is working doesn't mean we have the blog finished unfortunately! There is still the minor issue of getting the diamond-pi
nginx
http-proxy to forward requests to the new blog appropriately. Somehow I had assumed this would be fairly easy ... All I needed to do was change one line in the site definition file, from
proxy_pass http://127.0.0.1:2368;
to
proxy_pass http://diamond:2368;
What ensued was complete confusion. After fairly extensive debugging in the Chrome console followed by some complete guesswork I discovered that even though the whole site is served over https I should NOT tell the ghost docker container that it's URL was https://blog.bedewell.com/jos
and instead tell it to use http://blog.bedewell.com/jos
. I am still fairly unsure why this is the case, but without that being correct nothing worked!
Anyway - we are now completly running and writing new articles on a much new bloggin platform, that is dockerized!
UPDATE : That weirdness with needing to ensure that ghost was started with an http URL was nagging at me, and I noticed that I was ending up loading mixed-content (over http and https), which obviously was redirecting correctly on the server - but still it's just not right! Thankfully someone on the internet has already noticed this problematic issue. It appears that ghost requires the correct headers to be passed over to it. So now my nginx site definition is slightly different
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://diamond:2368;
In addition, I got myself another mail app password from gmail (in the same was as I got for forwardemail.net
) and configured ghost to use that as it's e-mail sending service.
Finally, it was proving annoying to have to configure lots of ghost options on the command line to the container so I wrote a trivial docker file
FROM ghost:latest
ADD config.production.json /var/lib/ghost/
Now I can update the config, rebuild my container image with a production config and redeplo
UPDATE 2: I further discovered that I forgot why I wasn't running the standard ghost container (when I pulled a new image to the machine!). I had to look at the Dockerfile
to see why I had one, etc. This lead to a better solution for getting my ghost config in the machine, simply using a volume mount of the config.production.json
file directly into /var/lib/ghost
.