Docker Ghost Blog

Dockerize Ghost Blog Site

Posted on

When i started to blog, I want my site to looks clean and simple, easy to manage, free dependencies from relational database and allow me to write in Markdown, also without any heavy plugins that clogging your site. It is when I discover Ghost and used it as my blogging platform.

Ghost is a blogging platform written in Node.js that used SQLite as a back-end database. It has well documentation and easily to start with. I follow the instruction and here we are. After installed in a local PC, I am impressed. All of my blog use Ghost running in VPS since then, and no going back for other blogging platform.

So, i have running blog site, it is when i want to migrate to other VPS. I started to look easy solution to migrate over existing blog to my new VPS. Then i found Docker. Ghost has official Docker Hub image, that you can use to contain your blog.

I encourage you to learn Docker first to get a brief knowledge what we will do.

Now, we can start our learning.

Backup

First, you need to backup your existing blog. You can refer to our previous tutorial about How to backup Ghost blog.

Install Docker

You need to install followings:

  • Docker
  • Docker Compose

Please refer to official site to install Docker in your system: https://www.docker.com/get-started

Create Docker Compose file

We will create a Docker Compose file to manage our Ghost container. Create a file named docker-compose.yml and make a docker configuration inside it, below is working copy of docker-compose.yml of my site.

version: '3.5'services:  ghost:    container_name: ghost    image: ghost:latest    restart: always    ports:      - "3001:2368"    environment:      url: https://www.waysquare.com    volumes:      - ./app/content:/var/lib/ghost/content

Then, you need to run it with this command in the same directory with docker-compose.yml file:

docker-compose up -d

It will expose port 3001 in our host to access ghost container blog.

Create a Reverse Proxy

To access port 3001 in our host and expose it to public internet, you need to create a reverse proxy. In this case i use Nginx as my web server and create a reverse proxy config, as shown below.

# SSLredirectStart - HTTP to HTTPS Redirectserver {        listen 80;        listen [::]:80;        server_name waysquare.com www.waysquare.com;        return 301 https://$host$request_uri;}# SSLredirectEnd# WWWredirectStart - Force WWW or non-WWW redirectserver {        listen 443 ssl http2;        listen [::]:443 ssl http2;        server_name waysquare.com;        # WebinolySSLstart        ssl_certificate /etc/letsencrypt/live/waysquare.com/fullchain.pem;        ssl_certificate_key /etc/letsencrypt/live/waysquare.com/privkey.pem;        ssl_stapling on;        ssl_stapling_verify on;        ssl_trusted_certificate /etc/letsencrypt/live/waysquare.com/chain.pem;        # WebinolySSLend        include common/headers-http.conf;        include common/headers-https.conf;        return 301 $scheme://www.waysquare.com$request_uri;}# WWWredirectEndserver {        listen 443 ssl http2;        listen [::]:443 ssl http2;        server_name www.waysquare.com;        # SSLstart        ssl_certificate /etc/letsencrypt/live/waysquare.com/fullchain.pem;        ssl_certificate_key /etc/letsencrypt/live/waysquare.com/privkey.pem;        ssl_stapling on;        ssl_stapling_verify on;        ssl_trusted_certificate /etc/letsencrypt/live/waysquare.com/chain.pem;        # SSLend        access_log /var/log/nginx/waysquare.com.access.log we_log;        error_log /var/log/nginx/waysquare.com.error.log;        location / {                proxy_set_header Host $host;                proxy_set_header X-Forwarded-Host $host;                proxy_set_header X-Forwarded-Server $host;                proxy_set_header X-Forwarded-Proto $scheme;                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                proxy_http_version 1.1;                proxy_set_header Upgrade $http_upgrade;                proxy_set_header Connection "upgrade";                proxy_redirect http://0.0.0.0:3001/ /;                proxy_redirect ws://0.0.0.0:3001/api/socket /api/socket;                proxy_pass http://0.0.0.0:3001/;                proxy_connect_timeout 300;                proxy_send_timeout    300;                proxy_read_timeout    300;        }}

Updating Ghost Container

If there are any Ghost newer version, it is easy to upgrade to the latest Ghost version. Go to directory where you docker-compose.ymlfile exist. Then follow below instructions.

Stop our Ghost container.

docker-compose down

Pull latest Ghost image to our local server.

docker-compose pull

Start the Ghost container again.

docker-compose up -d

Well done. You have learned how to containerize your Ghost blog with easy step. If you have any question don’t hesitate to ask in comment.

See you!

Loading...

Leave a Reply

Your email address will not be published. Required fields are marked *