Deploy Ghost With Docker
Ghost is a markdown blogging platform that allows one to easily post content that displays well on any screen size, such as a mobile phone.
Docker allows one to easily deploy applications such as Ghost without having to spend lots of time installing packages and reading installation instructions. This tutorial assumes you already have a docker host, or know how to install docker.
Steps
Create a docker-compose.yaml
file with the following content:
version: '3.1'
services:
ghost:
container_name: ghost
image: ghost:5.66.1
depends_on:
- db
restart: always
ports:
- "80:2368"
volumes:
- ./ghost-content:/var/lib/ghost/content
environment:
# see https://ghost.org/docs/config/#configuration-options
database__client: mysql
database__connection__host: db
database__connection__user: ghost
database__connection__password: ${GHOST_DB_PASSWORD}
database__connection__database: ghost
# this url value is just an example, and is likely wrong for your environment!
url: ${APP_URL}
NODE_ENV: production
db:
container_name: db
image: mysql:8.0
restart: always
# ports:
# - "3306:3306"
volumes:
- ./mysql-data:/var/lib/mysql
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: ghost
MYSQL_USER: ghost
MYSQL_PASSWORD: ${GHOST_DB_PASSWORD}
Then create a .env
file at the same level as your docker-compose.yaml
file with the following content:
# Specify the public URL for your site. This should include http:// or https:// based on your setup
# (you may be behind a terminating SSL proxy).
APP_URL="https://blog.mydaomain.com"
# Specify a random password for your database.
GHOST_DB_PASSWORD=putSomeRandomStrongStringHere
Then start everything up:
docker compose up
Register Yourself
Now go to your blog's URL,.but with /ghost
on the end, fill in the new user form, and then it will kick you through to the ghost dashboard.
Updating ghost
Whenever you want to update ghost, just update the version in your docker-compose file before running docker-compose down and up.
Conclusion
You have now seen how to setup your own blog using Ghost and Docker and should be able to navigate the menus on your own to create new posts. Now you may be interested in finding out how to add comments to your blog.
Appendix
Old Original Post (For Posterity)
Execute the following script to pull down the latest ghost docker image, and set up a directory to store data.
#!/bin/bash
if ! [ -n "$BASH_VERSION" ];then
echo "this is not bash, calling self with bash....";
SCRIPT=$(readlink -f "$0")
/bin/bash $SCRIPT
exit;
fi
# Pull down the ghost image
docker pull ghost:latest
# Set vars
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DATA_DIR="$HOME/ghost_volume"
CONTAINER_NAME="ghost_blog"
# Create volume area to store state and create base config there
mkdir -p $DATA_DIR
echo '{
"url": "http://my.domain.com",
"server": {
"port": 2368,
"host": "0.0.0.0"
},
"database": {
"client": "sqlite3",
"connection": {
"filename": "/var/lib/ghost/content/data/ghost.db"
}
},
"mail": {
"transport": "Direct"
},
"logging": {
"transports": [
"file",
"stdout"
]
},
"process": "systemd",
"paths": {
"contentPath": "/var/lib/ghost/content"
}
}' > $DATA_DIR/config.json
Once run, you will have a folder called ghost_volume
in your home directory. Inside that folder will be a folder called "content" that will store is all the content for the blog, and a file called config.js
which will be the configuration file for the blog.
Update the config.js
file within the ghost_volume directory and change the line:
"url": "http://my.domain.com",
... so that it points to your site's actual hostname or IP address.
Start the Container
Now you are ready to start your container. I recommend copy-pasting the script below into a file called start-blog.sh
that you can execute if you ever need to manually start your blog again.
# Set vars
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DATA_DIR="$HOME/ghost_volume"
CONTAINER_NAME="ghost_blog"
# Stop and remove the existing container if
# it is already running.
docker kill $CONTAINER_NAME
docker rm $CONTAINER_NAME
docker run \
-d \
--restart=always \
-p 80:2368 \
-v $DATA_DIR/content:/var/lib/ghost/content \
-v $DATA_DIR/config.json:/var/lib/ghost/config.production.json \
--name $CONTAINER_NAME \
ghost
Register Yourself
Navigate to your blog's IP or hostname and you should see the following screen:
Now add /admin
to the end of the URL and fill in the provided form to register yourself as the administrator, in order to make new posts.
First published: 16th August 2018