/ DevOps

How to update Ghost in docker?

Already some versions update for Ghost and Docker since last post for using Ghost on your self-hosted server. Therefore, we need synchronise them.

Update Docker

We use Amazon Web Service (AWS) EC2 as our host server, first we check the update from AWS official. $sudo yum update After that the docker version was updated to 1.9.1. As mentioned in last post, 1.8 and above are support docker cp command. That's great news.

Update Ghost

$docker pull ghost will update ghost image to the latest one. Then I want to update my ghost container. But unfortunately, my container include data in it that I can't just remove my old container and run a new one. Search and read some comments for how to upgrade docker container when after the image changed. The docker recommended Application container should not store any application data. Use Data Volumes to instead store data in application container. Then use the following way to upgrade container.

$docker pull <your_image_name>
$docker stop <your_container_name>
$docker rm -f <your_container_name>
$docker run --name <your_container_name> -v <host_path>:<container_path> <your_image_name>

With this situation, I need to backup and move to next step.


In case the update progress lost your data.

  • Very important config.js which is your configuraton for website, it under /<your ghost path>/config.js
  • You can copy the data from /<your ghost path>/content/ directly. This folder include your post data, uploaded images and themes.
  • Or you can use the method provided at http://<your-ghost-address>/ghost/settings/labs/, and after you deploy your new ghost site, you can use import your data at the same path.

Run Ghost with Docker

With new ghost image, and run
$docker run --name 31mins -p 80:2368 -e NODE_ENV=production -v ~/data:/ghost-override ghost
Shell console will show listen to and the url is http://localst:2368. This is what the config.js configed. Then I use the backup config.js to replace this file. And try to restart this container again. But failed. I tried a lot of way to restart the npm in container, but all failed. After about 2 hours with check comments from docker ghost community and google. I gave up. There is an issue in this docker image. The decide run Ghost without Docker in AWS EC2 first. When I have time, implement some feature with this docker image then will back to docker.

Run Ghost without Docker

Install Node

$sudo yum install nodejs npm --enablerepo=epel

Install Ghost

Grab the latest version of Ghost from Ghost.org:

$curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip

Unzip Ghost into the folder /var/www/ghost (recommended install location):

$unzip -uo ghost.zip -d /var/www/ghost

Move to the new ghost directory, and install Ghost (production dependencies only):

$cd /var/www/ghost && npm install --production

The steps above maybe need sudo to install, it depend on your user's permission.

Start Ghost

For easy switch and change the ghost to docker or like anywhere else you want, create a link to config.js.

e.g. I put my config.js and old data under ~/31mins/

$ln -s ~/31mins/config.js /var/www/ghost/config.js
$ln -s ~/31mins/content /var/www/ghost/content

With this configuration, $npm start --production will put all the data under ~/31mins/content.


  • Inspect docker container
    $docker inspect 31mins . You can got detail information for this container, it will help you to know docker container well.

  • How to add google analytics to Ghost? link

    • You have two ways to inject following javascript to support google analytics.
    • Use /ghost/Code Injection/ Add to header.
    • Second one is modify the default.hbs and add to head.
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

  ga('create', 'UA-72804803-1', 'auto');
  ga('send', 'pageview');