Starting your blog with Ghost and Docker

Setting up a new blog is a breeze with Ghost and Docker.

Starting your blog with Ghost and Docker

In my last post, I talked about Ghost and why I chose it as my blog platform. It's ideal for people who are looking to launch a blog quickly and easily. In this post, I will show you how straightforward it is to get started with docker and launch a Ghost blog

Docker is an excellent tool for packaging and deploying applications in a consistent and reproducible manner across various platforms. Developers should strongly consider learning about it and adding it to their portfolios. Non-developers can deploy Docker applications with Portainer. In this blog, I will demonstrate how to deploy Ghost using Docker. By using docker, you can quickly set up a Ghost blog, with all the necessary components already configured and ready to go. All you need to do is specify the configuration settings, such as the blog's domain name and port, and Docker will handle the rest

To start simply with a single docker command, you can execute the following command:

docker run -d -p 2368:2368 --name ghost-blog ghost:4

The command above will launch a blog on port 2368. Visit http://localhost:2368 from your browser to quickly start a new blog. If you are running this on a remote server, replace localhost with your IP address.

Browse around to see how it looks. However, any changes you make won't be permanent. This command also runs an older version of the blog, which might have fewer features. To create a more usable blog, you'll need to set up a database. Let's do that by using docker-compose to manage both the Ghost blog and the database required to store any blog posts you write.

We will configure Ghost and the database in docker-compose.yaml. Create a text file using any text editor, add the following content and save the file.

version: "3"
services:
  ghost_database:
    image: mysql:8-debian
    container_name: ghost_database
    restart: unless-stopped
    volumes:
      - type: bind
        source: /path/to/database
        target: /var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=password
  ghost:
    image: ghost:5-alpine
    container_name: ghost
    restart: unless-stopped
    depends_on:
      - ghost_database
    volumes:
      - type: bind
        source: /path/to/content
        target: /var/lib/ghost/content
    environment:
      database__client: mysql
      database__connection__host: ghost_database
      database__connection__user: root
      database__connection__password: password
      database__connection__database: ghost
      url: http://localhost:2368/
    ports:
      - 2368:2368

Create two directories, database and content. You can create the directories in the same directory where you saved your docker-compose.yaml. These directories will be used to store all the data and content that your blog needs. You have to replace the paths of the two directories in the docker-compose.yaml file with the ones you just created to make sure that the blog is using the directories you created. Furthermore, if you are using a remote server, you can also change localhost in url to the IP address of the server. Additionally, for security reasons, it is also important to change the database password to a more secure one. All in all, you will need to modify five lines in the docker-compose.yaml file for the blog to work properly.

...
- MYSQL_ROOT_PASSWORD=password
...
source: /path/to/database
...
source: /path/to/content
...
database__connection__password: password
...
url: http://localhost:2368/

Once all the directories and docker-compose.yaml file has been configured properly you can run this command to start your blog.

docker-compose up

Give your computer and internet a few minutes to download the Docker images. Once they're downloaded, Ghost will automatically configure your blog and database. When it's ready, you can visit http://localhost:2368/ from your browser to view your blog. This is enough to host a blog on a private computer or network, but you'll need additional configuration to make it accessible from the public internet.

Summary

Congratulations on setting up a new blog! Ghost is a modern and user-friendly blogging platform with plenty of customization tools. It has a clean dashboard, interface, and a variety of free modern themes.

Before you can share your blog with friends and family, or publish any content, there are a few more steps to take. For example, you need to secure your blog with a TLS certificate and set up a reverse proxy so it's reachable from the public internet. In my next post, I'll show you how to set up a free TLS certificate and reverse proxy for your blog.