Running Ghost 1.0.2 with Dokku
In this post, I will present to you how I achieved to run Ghost with Dokku. The objective is to deploy and run Ghost container to Dokku instance running on VPS server with installed Ubuntu 16.04 operating system. In the end, I will also secure running Ghost instance with SSL using Let’s Encrypt. So here is the list of things that should be done in order to get everything working:
- install Docker
- install Dokku
- deploy Ghost container to Dokku
- secure running Ghost instance with SSL using Let’s Encrypt
Installing Docker
In order to install Docker, I’ve written a small bash script which will do all the work. So here is the complete bash script:
#!/bin/bash
sudo true
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
If you have installed curl on your system just run following command:
curl -sSL https://git.io/v7ZK5 | sudo bash
After the script is finished you should have properly installed Docker on your system. To check if everything is working as expected run sudo docker version
which should result in the response similar to the following:
Install Dokku
To install latest stable version of Dokku you just have to run following shell commands:
wget https://raw.githubusercontent.com/dokku/dokku/v0.10.3/bootstrap.sh;
sudo DOKKU_TAG=v0.10.3 bash bootstrap.sh
After the installation process is completed Dokku is ready to setup SSH key and Virtualhost Settings. You can verify that everything is installed correctly with running following shell command dokku version
which should display you your dokku version number.
Setup SSH key and Virtualhost Settings
Navigate to your server IP address or domain you assigned to that IP address. You should see the configuration screen familiar to the one in this image. Here you can paste in your SSH public key and configure how should Virtualhost behave. After submitting the form everything is ready to deploy and run Ghost using Dokku.
Deploy Ghost with Dokku
We will deploy Ghost to the Dokku with Dockerfile. The way the installation process has changed in the latest major release of Ghost (version 1.0) has affected official Ghost Docker images and the way they are structured so there is no easy update.
One of the core devs of Ghost acburdine has put some effort to create working images for latest Ghost version with working ghost cli. So we will use his image in order to get Ghost working via Dokku.
So I have copied the Dockerfile
and docker-entrypoint.sh
files from the alpine
folder from here and place it in a folder on my computer.
To deploy and run copied Docker image on Dokku you have to first initialize a git repository in the folder where you placed the copied files. This is done with terminal command git initialize
. After initializing git repository we have to add files to git with command git add .
and afterward we have to add git remote URL to running Dokku with command git remote add dokku dokku@mydomain.com:mydomain.com
. This will push files to the Dokku and trigger build and deploy process. Note that this command will deploy ghost to the root domain (in our example to mydomain.com).
When the process is completed we should see demo Ghost blog when we open http://mydomain.com:2368 in our browser.
Notice that Ghost is running on port 2368
, so if we want it to run on default HTTP port 80
we should login to our Dokku server and run following command:
dokku proxy:ports-add mydomain.com http:80:2368
After nginx is reloaded we should see our default Ghost blog on the url http://mydomain.com. So now you can navigate to http://mydomain.com/ghost and begin to configure your Ghost blog.
Secure Ghost with SSL using Let’s Encrypt
At this point we have running Ghost blog instance on Dokku and the last this to do is to secure it with SSL connection. For this task we will use Let’s Encrypt Dokku plugin. Note that this plugin is in BETA stage and might have some bugs, however I have been using it for quite some time now and it has been working for me without any problems. First thing to do is to install plugin on Dokku server with the following command:
# if you have installed dokku version 0.5+ run
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
# if you have version 0.4 run
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git --committish dokku-0.4
After plugin installation is completed we need to configure our email address for purpose of obtaining certificates from Let’s Encrypt. This is done with the command:
dokku config:set --no-restart mydomain.com DOKKU_LETSENCRYPT_EMAIL=my.email@host.com
To secure our Dokku application with HTTS we have to run command: dokku letsencrypt domain.com
When process is finished we should be able to access our Ghost blog via https://mydomain.com.
One last thing to do is to configure plugin to run automated checks if installed certificate is expired and in case if it is plugin will automatically renew it. We can accomplish this with executing:
dokku letsencrypt:cron-job --add
Objective completed!
We finally completed installing Docker and Dokku and deploy Ghost blog to the server. If you like this blog post or you having some trouble doing the same on your machine please comment down below. And of course feel free to share this post or follow me on Twitter. Have a nice day!